Module: NinjaModel::Reflection::ClassMethods
- Defined in:
- lib/ninja_model/reflection.rb
Instance Method Summary collapse
- #create_reflection(macro, name, options, ninja_model) ⇒ Object
- #reflect_on_aggregation(aggregation) ⇒ Object
- #reflect_on_association(association) ⇒ Object
- #reflections ⇒ Object
Instance Method Details
#create_reflection(macro, name, options, ninja_model) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/ninja_model/reflection.rb', line 11 def create_reflection(macro, name, , ninja_model) case macro when :has_many, :belongs_to, :has_one reflection = Reflection::AssociationReflection.new(macro, name, , ninja_model) when :composed_of reflection = AggregateReflection.new(macro, name, , ninja_model) else raise NotImplementedError, "NinjaModel does not currently support #{macro} associations." end self.reflections = self.reflections.merge(name => reflection) reflection end |
#reflect_on_aggregation(aggregation) ⇒ Object
29 30 31 |
# File 'lib/ninja_model/reflection.rb', line 29 def reflect_on_aggregation(aggregation) reflections[aggregation].is_a?(AggregateReflection) ? reflections[aggregation] : nil end |
#reflect_on_association(association) ⇒ Object
33 34 35 |
# File 'lib/ninja_model/reflection.rb', line 33 def reflect_on_association(association) reflections[association].is_a?(Reflection::AssociationReflection) ? reflections[association] : nil end |
#reflections ⇒ Object
25 26 27 |
# File 'lib/ninja_model/reflection.rb', line 25 def reflections read_inheritable_attribute(:reflections) || write_inheritable_attribute(:reflections, {}) end |