Module: Mongoid::Mirrored::ClassMethods
- Includes:
- HelperMethods, MirrorMethods, RootMethods
- Defined in:
- lib/mongoid-mirrored/mirrored_in.rb
Instance Method Summary collapse
Methods included from HelperMethods
#extract_options, #root_association, #symbol_to_class
Methods included from RootMethods
#define_create_mirrors, #define_destroy_mirrors, #define_root_callbacks, #define_update_mirrors, #write_fields_with_options
Methods included from MirrorMethods
#define_after_create_callback, #define_after_create_siblings, #define_after_destroy_callback, #define_after_destroy_siblings, #define_after_update_callback, #define_after_update_siblings, #define_mirror_attributes, #define_mirror_callbacks, #embeds_mirror
Instance Method Details
#mirrored_in(*args, &block) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/mongoid-mirrored/mirrored_in.rb', line 19 def mirrored_in(*args, &block) (*args) { yield } @root_klass = self # creates a Mirrored class for each embedding model [:all].each do || self.[:current] = mirror_klass = Class.new do include Mongoid::Document # includes all fields and methods declared when calling mirrored_in class_eval &block end self.mirror_klass = mirror_klass define_mirror_attributes define_mirror_callbacks = symbol_to_class() # Creates the mirrored class Embedding::Root .const_set self.name, mirror_klass end end |