Started getting error below with edge mongoid.
aki@rydeen~/Dropbox/RubyProjects/zitta-orders > rails c
Loading development environment (Rails 3.2.6)
ruby-1.9.2-p290 :001 > ap 'wheee'
NameError: uninitialized constant BSON
from /Users/aki/.rvm/gems/ruby-1.9.2-p290/gems/awesome_print-1.0.2/lib/awesome_print/ext/mongoid.rb:23:in `cast_with_mongoid'
from /Users/aki/.rvm/gems/ruby-1.9.2-p290/gems/awesome_print-1.0.2/lib/awesome_print/formatter.rb:24:in `format'
from /Users/aki/.rvm/gems/ruby-1.9.2-p290/gems/awesome_print-1.0.2/lib/awesome_print/inspector.rb:104:in `unnested'
from /Users/aki/.rvm/gems/ruby-1.9.2-p290/gems/awesome_print-1.0.2/lib/awesome_print/inspector.rb:71:in `awesome'
from /Users/aki/.rvm/gems/ruby-1.9.2-p290/gems/awesome_print-1.0.2/lib/awesome_print/core_ext/kernel.rb:10:in `ai'
from /Users/aki/.rvm/gems/ruby-1.9.2-p290/gems/awesome_print-1.0.2/lib/awesome_print/core_ext/kernel.rb:15:in `ap'
from (irb):1
from /Users/aki/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.6/lib/rails/commands/console.rb:47:in `start'
from /Users/aki/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.6/lib/rails/commands/console.rb:8:in `start'
from /Users/aki/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.6/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
This is because awesome_print uses ::BSON::ObjectId constant which got renamed to Moped::BSON::ObjectId (by commit http://goo.gl/RSZos)
To get ap working again, add the following to bottom of your application.rb file:
BSON=Moped::BSON
Ok I solved the problem by specifing
Moped::BSON = BSON
before actually using the awesome printing features.It seems that, for the version of the libraries I'm using (i.e.
mongoid 4.0.0
,moped 2.0.0
andawesome_print 1.2.0
), theBSON
constant is correctly defined in contrast to theMoped::BSON
.I hope this can be helpful for the ones will face the same problem.
Cheers.
[EDIT]
Just for the record I've encapsulated the over mentioned "patch" inside a module:
In this way all you should do is to
include PatchedAwesomePrint
instead ofrequire 'awesome_print'
.As before I hope this can be helpful but moreover I hope that my refined solution will not break things under specific circumstances. If this is the case forgive me and don't hesitate to point it out by writing it down here.
Cheers.