phoet / asin

:books: :package: Amazon Simple INterface - Support for ItemLookup, SimilarityLookup, Search, BrowseNode and Cart Operations
http://asin.herokuapp.com/
167 stars 59 forks source link

ASIN::Configuration clashing with a Configuration model already in my app #11

Closed snoblenet closed 13 years ago

snoblenet commented 13 years ago

Hi there,

My app has a Configuration.rb model. Short of renaming it, how can avoid the clash with ASIN::Configuration?

When I comment out the contents of asin.rb (to allow the app to start), enter the rails console, and type ASIN:Configuration, I see:

Configuration(id: integer, name: string, cached_slug: string, model_id: integer, configured_ram: float, requires: string, created_at: datetime, updated_at: datetime)

These are the attributes of my app's existing Configuration model, not ASIN:Configuration.

Many thanks,

Steven.

phoet commented 13 years ago

hi steven,

you application should not clash in any way, because the gem is using the namespace ASIN to prevent exactly that. unless you are using the same namespace there should not be any problem.

please always provide a stacktrace of the error you get.

snoblenet commented 13 years ago

Hi there,

Trace pasted below.

I thought it might be that asin.rb was attempting to work with my Configuration class because ASIN, and therefore ASIN:Configuration, had not yet loaded. So I added the 'require' and 'include' statements to asin.rb. But still I get this result:

iMac-001EC20A3C44-3:suthu steven$ rails console
/Users/steven/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.0.10/lib/active_record/base.rb:1014:in `method_missing': undefined method `configure' for #<Class:0x00000101509ab8> (NoMethodError)
    from /Users/steven/Code/suthu/config/initializers/asin.rb:2:in `<top (required)>'
    from /Users/steven/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.10/lib/active_support/dependencies.rb:235:in `load'
    from /Users/steven/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.10/lib/active_support/dependencies.rb:235:in `block in load'
    from /Users/steven/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.10/lib/active_support/dependencies.rb:225:in `block in load_dependency'
    from /Users/steven/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.10/lib/active_support/dependencies.rb:593:in `new_constants_in'
    from /Users/steven/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.10/lib/active_support/dependencies.rb:225:in `load_dependency'
    from /Users/steven/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.10/lib/active_support/dependencies.rb:235:in `load'
    from /Users/steven/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.10/lib/rails/engine.rb:201:in `block (2 levels) in <class:Engine>'
    from /Users/steven/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.10/lib/rails/engine.rb:200:in `each'
    from /Users/steven/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.10/lib/rails/engine.rb:200:in `block in <class:Engine>'
    from /Users/steven/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.10/lib/rails/initializable.rb:25:in `instance_exec'
    from /Users/steven/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.10/lib/rails/initializable.rb:25:in `run'
    from /Users/steven/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.10/lib/rails/initializable.rb:50:in `block in run_initializers'
    from /Users/steven/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.10/lib/rails/initializable.rb:49:in `each'
    from /Users/steven/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.10/lib/rails/initializable.rb:49:in `run_initializers'
    from /Users/steven/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.10/lib/rails/application.rb:134:in `initialize!'
    from /Users/steven/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.10/lib/rails/application.rb:77:in `method_missing'
    from /Users/steven/Code/suthu/config/environment.rb:5:in `<top (required)>'
    from /Users/steven/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.10/lib/rails/application.rb:103:in `require'
    from /Users/steven/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.10/lib/rails/application.rb:103:in `require_environment!'
    from /Users/steven/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.10/lib/rails/commands.rb:22:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

It's saying the configure method is missing because it's not a method of my Configuration class.

phoet commented 13 years ago

please always provide the code that is causing the error!

snoblenet commented 13 years ago

As in asin.rb? It's:

include ASIN::Client
ASIN::Configuration.configure do |config|
  config.secret        = 'redacted'
  config.key           = 'redacted'
  config.associate_tag = 'redacted'
end

Same result previously with:


ASIN::Configuration.configure do |config|
  config.secret        = 'redacted'
  config.key           = 'redacted'
  config.associate_tag = 'redacted'
end

Gemfile reads:


source 'http://rubygems.org'

  gem 'rails'
  gem 'rake', '0.8.7'
  gem 'ruby-debug19'
  gem 'sqlite3'
  gem 'nokogiri'
  gem 'friendly_id'
  gem 'chronic'
  gem 'syntax'
  gem 'table_parser'
  gem 'rails-backup-migrate'
  gem 'crumble', :require => 'breadcrumb'
  gem 'asin'
  gem 'httpclient'
  gem 'rash'

group :development, :test do
  gem 'rails-backup-migrate'
  gem 'spork'
  gem 'rspec-rails'
  gem 'cucumber-rails'
  gem 'capybara'
  gem 'database_cleaner'
  gem 'haml'
  gem 'haml-rails'
  gem 'compass'
  gem 'compass-susy-plugin'
  gem 'launchy'
  gem 'compass'
  gem 'compass-colors'
  gem 'compass-susy-plugin'
  gem 'rb-fsevent'
end
phoet commented 13 years ago

it might be the case that your ruby version has problems autoloading the asin classes. i saw that lately with some jruby versions.

try this variant:

require 'asin/configuration'

ASIN::Configuration.configure do |config|
  config.secret        = 'redacted'
  config.key           = 'redacted'
  config.associate_tag = 'redacted'
end

if i were you, i would also move the ruby-debug gem to the testing group.

snoblenet commented 13 years ago

Thanks! But no luck...


iMac-001EC20A3C44-3:suthu steven$ rails console
/Users/steven/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.10/lib/active_support/dependencies.rb:239:in `require': no such file to load -- asin/configuration (LoadError)
    from /Users/steven/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.10/lib/active_support/dependencies.rb:239:in `block in require'
    from /Users/steven/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.10/lib/active_support/dependencies.rb:225:in `block in load_dependency'
    from /Users/steven/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.10/lib/active_support/dependencies.rb:593:in `new_constants_in'
    from /Users/steven/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.10/lib/active_support/dependencies.rb:225:in `load_dependency'
    from /Users/steven/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.10/lib/active_support/dependencies.rb:239:in `require'
    from /Users/steven/Code/suthu/config/initializers/asin.rb:1:in `<top (required)>'
    from /Users/steven/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.10/lib/active_support/dependencies.rb:235:in `load'
    from /Users/steven/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.10/lib/active_support/dependencies.rb:235:in `block in load'
    from /Users/steven/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.10/lib/active_support/dependencies.rb:225:in `block in load_dependency'
    from /Users/steven/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.10/lib/active_support/dependencies.rb:593:in `new_constants_in'
    from /Users/steven/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.10/lib/active_support/dependencies.rb:225:in `load_dependency'
    from /Users/steven/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.10/lib/active_support/dependencies.rb:235:in `load'
    from /Users/steven/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.10/lib/rails/engine.rb:201:in `block (2 levels) in <class:Engine>'
    from /Users/steven/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.10/lib/rails/engine.rb:200:in `each'
    from /Users/steven/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.10/lib/rails/engine.rb:200:in `block in <class:Engine>'
    from /Users/steven/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.10/lib/rails/initializable.rb:25:in `instance_exec'
    from /Users/steven/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.10/lib/rails/initializable.rb:25:in `run'
    from /Users/steven/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.10/lib/rails/initializable.rb:50:in `block in run_initializers'
    from /Users/steven/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.10/lib/rails/initializable.rb:49:in `each'
    from /Users/steven/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.10/lib/rails/initializable.rb:49:in `run_initializers'
    from /Users/steven/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.10/lib/rails/application.rb:134:in `initialize!'
    from /Users/steven/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.10/lib/rails/application.rb:77:in `method_missing'
    from /Users/steven/Code/suthu/config/environment.rb:5:in `<top (required)>'
    from /Users/steven/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.10/lib/rails/application.rb:103:in `require'
    from /Users/steven/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.10/lib/rails/application.rb:103:in `require_environment!'
    from /Users/steven/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.10/lib/rails/commands.rb:22:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'
phoet commented 13 years ago

you could try moving the configuration-stuff to where you are using asin. i have no idea what the problem is that you are experiencing. maybe you are missing some bundler setup or the like.

i am using this configuration style on my own. have a look here: https://github.com/phoet/basement/blob/master/config/initializers/asin.rb

snoblenet commented 13 years ago

I tried adding ASIN to a new app that did not have my Configuration class and I got this:


/Users/steven/Code/blah/config/initializers/asin.rb:1:in `<top (required)>': uninitialized constant ASIN::Configuration (NameError)
    from /Users/steven/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.10/lib/rails/engine.rb:201:in `block (2 levels) in <class:Engine>'
    from /Users/steven/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.10/lib/rails/engine.rb:200:in `each'
    from /Users/steven/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.10/lib/rails/engine.rb:200:in `block in <class:Engine>'
    from /Users/steven/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.10/lib/rails/initializable.rb:25:in `instance_exec'
    from /Users/steven/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.10/lib/rails/initializable.rb:25:in `run'
    from /Users/steven/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.10/lib/rails/initializable.rb:50:in `block in run_initializers'
    from /Users/steven/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.10/lib/rails/initializable.rb:49:in `each'
    from /Users/steven/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.10/lib/rails/initializable.rb:49:in `run_initializers'
    from /Users/steven/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.10/lib/rails/application.rb:134:in `initialize!'
    from /Users/steven/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.10/lib/rails/application.rb:77:in `method_missing'
    from /Users/steven/Code/blah/config/environment.rb:5:in `<top (required)>'
    from /Users/steven/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.10/lib/rails/application.rb:103:in `require'
    from /Users/steven/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.10/lib/rails/application.rb:103:in `require_environment!'
    from /Users/steven/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.10/lib/rails/commands.rb:22:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

iMac-001EC20A3C44-3:blah steven$ bundle install
Using rake (0.9.2) 
Using abstract (1.0.0) 
Using activesupport (3.0.10) 
Using builder (2.1.2) 
Using i18n (0.5.0) 
Using activemodel (3.0.10) 
Using erubis (2.6.6) 
Using rack (1.2.3) 
Using rack-mount (0.6.14) 
Using rack-test (0.5.7) 
Using tzinfo (0.3.29) 
Using actionpack (3.0.10) 
Using mime-types (1.16) 
Using polyglot (0.3.2) 
Using treetop (1.4.10) 
Using mail (2.2.19) 
Using actionmailer (3.0.10) 
Using arel (2.0.10) 
Using activerecord (3.0.10) 
Using activeresource (3.0.10) 
Using crack (0.1.8) 
Using hashie (1.1.0) 
Using httpclient (2.2.1) 
Using asin (0.0.8) 
Using bundler (1.0.18) 
Using rdoc (3.9.2) 
Using thor (0.14.6) 
Using railties (3.0.10) 
Using rails (3.0.10) 
Using rash (0.3.1) 
Using sqlite3 (1.3.4) 
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
phoet commented 13 years ago

if you want to see a working example, i just created a stub with rails 3.1 using asin: https://github.com/phoet/asin_web

snoblenet commented 13 years ago

I moved asin up in the Gemfile to just below sqlite3, commented out httpclient and rash, ran bundle update (upgrading from Raild 3.0.5 to Rails 3.1 in the process), and it started working. :-)

phoet commented 13 years ago

does not make sense to me, but i would not be surprised if bundle just fucked up somehow. not the first time honestly...

phoet commented 12 years ago

hi steven,

i created a little example application with some asin snippets. this might be helpful for problem like yours:

http://asin.heroku.com/

snoblenet commented 12 years ago

Cool, thx!