Module: Mongoid::Mirrored::HelperMethods
- Included in:
- ClassMethods
- Defined in:
- lib/mongoid-mirrored/helper_methods.rb
Instance Method Summary collapse
- #extract_options(*args) ⇒ Object
-
#root_association ⇒ Object
name of the association used by the embedding class eg: comments.
- #symbol_to_class(symbol) ⇒ Object
Instance Method Details
#extract_options(*args) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/mongoid-mirrored/helper_methods.rb', line 4 def (*args) = args. self. = {:all => args, :current => nil} self. = # set defaults self.[:sync_events] ||= :all self.[:sync_events] = [self.[:sync_events]] unless [:sync_events].is_a? Array self.[:sync_direction] ||= :both self.[:replicate_to_siblings] = true if self.[:replicate_to_siblings].nil? self.[:inverse_of] ||= :many self.[:index] = false if self.[:index].nil? self.[:background_index] = false if self.[:background_index].nil? end |
#root_association ⇒ Object
name of the association used by the embedding class eg: comments
21 22 23 24 25 |
# File 'lib/mongoid-mirrored/helper_methods.rb', line 21 def root_association inverse_of = @root_klass.name.underscore inverse_of = inverse_of.pluralize if [:inverse_of] == :many inverse_of end |
#symbol_to_class(symbol) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/mongoid-mirrored/helper_methods.rb', line 27 def symbol_to_class(symbol) begin symbol.to_s.classify.constantize rescue Object.const_set symbol.to_s.classify, Class.new ensure symbol.to_s.classify.constantize end end |