Skip to content

AboutGem assignment submission. #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

codeblahblah
Copy link

@jwo Completed the Panda and Tiger level.
The app is hosted here: http://obscure-badlands-2253.herokuapp.com/

gem 'sinatra'
gem 'sinatra-contrib'
gem 'shotgun'
gem 'about_drammopo', '~> 0.1.0', github: 'drammopo/about_drammopo'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice use here to load the gem directly from github. You'll use this when you fork a repository.

@jwo
Copy link
Member

jwo commented Mar 17, 2014

Great job!

@codeblahblah
Copy link
Author

@jwo Awesome! On to the Eagle level. I'm not too sure where to start but
will look at the Devise source code. Are there any simpler gems that I can
follow for this exercise? Especially, in terms of the database integration
/ Rake tasks?

On Monday, March 17, 2014, Jesse Wolgamott [email protected] wrote:

Great job!

Reply to this email directly or view it on GitHubhttps://github.com//pull/7#issuecomment-37819181
.

"When you are tired of being yourself then you can be ordinary." - dudu

@jwo
Copy link
Member

jwo commented Mar 17, 2014

Devise is a Rails engine (so has to be used in Rails), and it's extremely complicated.

I have not used this, but it looks useful for sinatra and activerecord: https://github.com/janko-m/sinatra-activerecord

@codeblahblah
Copy link
Author

@jwo I'm all over the place as far as implementing the Eagle level.
The adventure gem code can be found here:
https://github.com/drammopo/adventure
Am I on the right track?
At the moment I'm just trying to get the specs to pass...

@jwo
Copy link
Member

jwo commented Mar 19, 2014

Adventure gem looks great. Other devs have used it as ActiveRecord, though it looks like you're using it as more just ruby classes. Either work.

@codeblahblah
Copy link
Author

@jwo I'm trying to do the same...use it as ActiveRecord.
Getting this error when running the rspec command:
adventure/lib/adventure/page.rb:1:in `<top (required)>': uninitialized
constant ActiveRecord (NameError)

How do I overcome this error?

On 19 March 2014 19:57, Jesse Wolgamott [email protected] wrote:

Adventure gem looks great. Other devs have used it as ActiveRecord, though
it looks like you're using it as more just ruby classes. Either work.

Reply to this email directly or view it on GitHubhttps://github.com//pull/7#issuecomment-38085100
.

"When you are tired of being yourself then you can be ordinary." - dudu

@jwo
Copy link
Member

jwo commented Mar 19, 2014

Why do you do this?

https://github.com/drammopo/adventure/blob/master/lib/adventure.rb#L4

require “active_record"

Jesse Wolgamott @ Comal Productions, Inc.
Web. Mobile. Design. Training.
@jwo
http://comalproductions.com

On Wednesday, March 19, 2014 at 3:58 PM, drammopo wrote:

@jwo I'm trying to do the same...use it as ActiveRecord.
Getting this error when running the rspec command:
adventure/lib/adventure/page.rb:1:in `<top (required)>': uninitialized
constant ActiveRecord (NameError)

How do I overcome this error?

On 19 March 2014 19:57, Jesse Wolgamott <[email protected] (mailto:[email protected])> wrote:

Adventure gem looks great. Other devs have used it as ActiveRecord, though
it looks like you're using it as more just ruby classes. Either work.

Reply to this email directly or view it on GitHubhttps://github.com//pull/7#issuecomment-38085100
.

"When you are tired of being yourself then you can be ordinary." - dudu


Reply to this email directly or view it on GitHub (#7 (comment)).

@jwo
Copy link
Member

jwo commented Mar 19, 2014

Another possibility:

You did not edit your gemspec, you edited your Gemfile on the gem itself. So, it will not install that when you use it.

Nothing is loading ActiveRecord because you haven’t told it that it needed to be loaded.

Jesse Wolgamott @ Comal Productions, Inc.
Web. Mobile. Design. Training.
@jwo
http://comalproductions.com

On Wednesday, March 19, 2014 at 4:01 PM, Jesse Wolgamott wrote:

Why do you do this?

https://github.com/drammopo/adventure/blob/master/lib/adventure.rb#L4

require “active_record"

Jesse Wolgamott @ Comal Productions, Inc.
Web. Mobile. Design. Training.
@jwo
http://comalproductions.com

On Wednesday, March 19, 2014 at 3:58 PM, drammopo wrote:

@jwo I'm trying to do the same...use it as ActiveRecord.
Getting this error when running the rspec command:
adventure/lib/adventure/page.rb:1:in `<top (required)>': uninitialized
constant ActiveRecord (NameError)

How do I overcome this error?

On 19 March 2014 19:57, Jesse Wolgamott <[email protected] (mailto:[email protected])> wrote:

Adventure gem looks great. Other devs have used it as ActiveRecord, though
it looks like you're using it as more just ruby classes. Either work.

Reply to this email directly or view it on GitHubhttps://github.com//pull/7#issuecomment-38085100
.

"When you are tired of being yourself then you can be ordinary." - dudu


Reply to this email directly or view it on GitHub (#7 (comment)).

@codeblahblah
Copy link
Author

@jwo Remembered that you can load dependencies as:

  gem.add_development_dependency "rspec"
  gem.add_development_dependency 'rake'
  gem.add_development_dependency 'activesupport'
  gem.add_development_dependency 'activerecord'
  gem.add_development_dependency 'pg'

Still have the same error....
In terms of the lib directory, should I have the same structure as in the original game?
with
|-------lib
|------adventure
|-----------adventure.rb
|-------models
|-------db
|--------config

@codeblahblah
Copy link
Author

@jwo Changed page.rb to

require "active_record"
class Page < ActiveRecord::Base ; end

Gettting a "better" error in that the specs run....with the error ActiveRecord::ConnectionNotEstablished

@codeblahblah
Copy link
Author

@jwo In Episode3, we have a db directory which uses db/migrate/...rb , seed.rb and setup.rb files to initialize the app.
Should I keep the same directory structure?
Also, this kinda helped with ideas around defining the Rake tasks:
http://blog.aizatto.com/2007/05/27/activerecord-migrations-without-rails/

@jwo
Copy link
Member

jwo commented Mar 19, 2014

With eagle assignments, there's no "should"..... You need to be 100% sure on the load order:

  1. Load your DB 
  2. Load your gem

On Wed, Mar 19, 2014 at 4:56 PM, drammopo [email protected]
wrote:

@jwo In Episode3, we have a db directory which uses db/migrate/...rb , seed.rb and setup.rb files to initialize the app.
Should I keep the same directory structure?
Also, this kinda helped with ideas around defining the Rake tasks:

http://blog.aizatto.com/2007/05/27/activerecord-migrations-without-rails/

Reply to this email directly or view it on GitHub:
#7 (comment)

@codeblahblah
Copy link
Author

@jwo Do. Or do not. There is no try?
Lemme see how much further I can go before getting stuck.

@jwo
Copy link
Member

jwo commented Mar 19, 2014

🤘

On Wed, Mar 19, 2014 at 5:15 PM, drammopo [email protected]
wrote:

@jwo Do. Or do not. There is no try?

Lemme see how much further I can go before getting stuck.

Reply to this email directly or view it on GitHub:
#7 (comment)

@codeblahblah
Copy link
Author

@jwo Been struggling with the Eagle level for sometime.
Here's the direction I'm trying to take:
https://github.com/drammopo/adventure

I'd like to run the tasks below in order to bootstrap the gem within the Sinatra app....(but I think it impossible)
rake adventure:migrate
rake adventure:seed

Can I have custom tasks as above?
Should a Ruby gem have "seed" data? If "yes", how does one load such fixtures?

@jwo
Copy link
Member

jwo commented Apr 8, 2014

So let's say you wanted to have

rake adventure:migrate
rake adventure:seed

This is possible! In here (https://github.com/drammopo/adventure/tree/master/lib) you need a "tasks" directory, with a adventure.rake file that clients can run.

You'll instruct your clients to load adventure/tasks/adventure.rake. This will make those tasks available for use.

See also:
0. http://stackoverflow.com/questions/15446153/ruby-rake-load-tasks-from-a-gem
0. http://blog.nathanhumbert.com/2010/02/rails-3-loading-rake-tasks-from-gem.html

You'll see this is pretty much exactly what is done here https://github.com/janko-m/sinatra-activerecord

@codeblahblah
Copy link
Author

@jwo Thanks for the clues.
Will follow-up once I have the gem working.

My latest version of the gem is up.
All the specs are passing and I'm connecting to SQLite for those.
What is the advantage of modularising the models besides namespacing? i.e.

module Adventure
  class Page < ActiveRecord::Base
  end
end

module Adventure
  class Book
  end
end

At the moment everything seems to work...fine.

@jwo
Copy link
Member

jwo commented Apr 8, 2014

This is a model that is backed by a database

module Adventure
  class Page < ActiveRecord::Base
  end
end

This is a plain ruby class, without a database table behind it

module Adventure
  class Book
  end
end

If you do not add your classes to a module, they exist in a global namespace. So, let's say you have an Item.... If you have a gem with a class Item, you are basically preventing your clients from adding a class named Item to their apps. (boo).

But, if you have YourAwesomeApp::Item, then it it protected, and your clients can define an Item of their own.

@codeblahblah
Copy link
Author

@jwo Makes perfect sense.
I'm unable to load the tasks/adventure.rake file.
Do I have to explicitly load the extension is it a .rake and not .rb file?

@codeblahblah
Copy link
Author

@jwo From :http://blog.smartlogicsolutions.com/2009/05/26/including-external-rake-files-in-your-projects-rakefile-keep-your-rake-tasks-organized/

Rake assumes the ‘require’d files end in .rb, so it won’t find your .rake files. You need to import rake files:

import 'lib/some_rake_file'

This is fine for individual files, but I wanted to include all files that end in .rake in my tasks dir:

Dir.glob('tasks/*.rake').each { |r| import r }

…and there you go.

@codeblahblah
Copy link
Author

@jwo Seems this is the way to go about it..
https://github.com/janko-m/sinatra-activerecord/blob/master/lib/sinatra/activerecord/rake.rb
Looks like a lot of work.
Think I'll move to implementing the gem all together and visit this later.

@jwo
Copy link
Member

jwo commented Apr 8, 2014

Dir.glob('tasks/*.rake').each { |r| import r }

Perfect!

Looks like a lot of work.

Yep. good choice.

@codeblahblah
Copy link
Author

@jwo Sucker for punishment that I am...I kinda started but will stop while I'm ahead!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants