Skip to content

Instantly share code, notes, and snippets.

@arsduo
Created June 15, 2012 12:14
Show Gist options
  • Save arsduo/2936175 to your computer and use it in GitHub Desktop.
Save arsduo/2936175 to your computer and use it in GitHub Desktop.
???
1.9.2p290 :007 > Mongoid::Document.send(:include, ActiveModel::SerializerSupport)
=> Mongoid::Document
1.9.2p290 :008 > Mongoid::Document.include?(ActiveModel::SerializerSupport)
=> false
1.9.2p290 :009 > Mongoid::Document.included_modules
=> [ProprietaryModule]
1.9.2p290 :014 > Mongoid::Document.ancestors
=> [Mongoid::Document, ProprietaryModule]
@arsduo
Copy link
Author

arsduo commented Jun 15, 2012

Mongoid is being loaded by a gem that's including the ProprietaryModule in it; this code (executed here in a rails console) should be executed inside an initializer (per http://autonomousmachine.com/posts/2012/5/5/use-active-model-serializers-with-mongoid).

@arsduo
Copy link
Author

arsduo commented Jun 15, 2012

Mongoid::Document doesn't appear to define its own include method, though I haven't dug through all the modules it includes.

@fxn
Copy link

fxn commented Jun 15, 2012

Cannot reproduce in isolation:

fxn@cauchy:~/tmp $ cat foo.rb
require 'rubygems'
require 'mongoid'

module M
end

Mongoid::Document.send(:include, M)
p Mongoid::Document.ancestors
fxn@cauchy:~/tmp $ ruby foo.rb 2>/dev/null
[Mongoid::Document, M]

@josepjaume
Copy link

OK Alex, I didn't read your full comment, sorry :D

@josepjaume
Copy link

Could it be a 1.9.2-specific issue? What ruby version are you using, @fxn?

@arsduo
Copy link
Author

arsduo commented Jun 15, 2012

I'm on ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin11.3.0]. I can't rule out that it has something to do with all the other gems (including Rails) that I'm loading...but on the plus side, I've figured out how to do what I need to do in Mongoid 3 without having to switch serializers, so while I'd like to do that and figure this out, it's a lot less urgent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment