Skip to content
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

Candy shouldn't try to connect to localhost just by requiring it #4

Closed
anaisbetts opened this issue May 3, 2010 · 1 comment
Closed

Comments

@anaisbetts
Copy link

Spinning up an irb prompt and running:

require 'candy'

Causes the Candy module to create a MongoDb connection to localhost, without actually using any Candy objects. Here's the stack, I'm using a git submodule that is a mirror of this repo:

➜ Istoria git:(version_two) ✗ bundle exec irb
irb(main):001:0> require 'candy'
Mongo::ConnectionFailure: failed to connect to any given host:port
from /home/paul/.bundle/ruby/1.9.1/gems/mongo-1.0/lib/mongo/connection.rb:435:in connect_to_master' from /home/paul/.bundle/ruby/1.9.1/gems/mongo-1.0/lib/mongo/connection.rb:112:ininitialize'
from /home/paul/Projects/Istoria/vendor/candy/lib/candy/crunch.rb:50:in new' from /home/paul/Projects/Istoria/vendor/candy/lib/candy/crunch.rb:50:inconnection'
from /home/paul/Projects/Istoria/vendor/candy/lib/candy/crunch.rb:72:in db' from /home/paul/Projects/Istoria/vendor/candy/lib/candy/crunch.rb:132:indb'
from /home/paul/Projects/Istoria/vendor/candy/lib/candy/crunch.rb:166:in collection=' from /home/paul/Projects/Istoria/vendor/candy/lib/candy/hash.rb:23:inclass:CandyHash'
from /home/paul/Projects/Istoria/vendor/candy/lib/candy/hash.rb:19:in <module:Candy>' from /home/paul/Projects/Istoria/vendor/candy/lib/candy/hash.rb:3:in<top (required)>'
from /home/paul/Projects/Istoria/vendor/candy/lib/candy/collection.rb:2:in require' from /home/paul/Projects/Istoria/vendor/candy/lib/candy/collection.rb:2:in<top (required)>'
from /home/paul/Projects/Istoria/vendor/candy/lib/candy.rb:4:in require' from /home/paul/Projects/Istoria/vendor/candy/lib/candy.rb:4:inblock in <top (required)>'
from /home/paul/Projects/Istoria/vendor/candy/lib/candy.rb:4:in each' from /home/paul/Projects/Istoria/vendor/candy/lib/candy.rb:4:in<top (required)>'
from (irb):1:in `require'
from (irb):1

@SFEley
Copy link
Owner

SFEley commented May 4, 2010

Good catch! You're completely right -- the intention was to have lazy everything, and not make any connections until the first data operation is performed. But I was sloppy and didn't test it on a machine that didn't have MongoDB running, so I didn't notice that an attempt to set a collection name was causing a cascade of references. I also think the "require everything" approach in the main candy.rb file was too greedy.

It's fixed now. Please try the latest version (gemmed and tagged as 0.2.6) and let me know if you still have any problems. Thanks very much for pointing this out.

This issue was closed.
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

No branches or pull requests

2 participants