Module: NinjaModel::Reflection::ClassMethods

Defined in:
lib/ninja_model/reflection.rb

Instance Method Summary collapse

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, options, ninja_model)
  case macro
  when :has_many, :belongs_to, :has_one
    reflection = Reflection::AssociationReflection.new(macro, name, options, ninja_model)
  when :composed_of
    reflection = AggregateReflection.new(macro, name, options, 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

#reflectionsObject



25
26
27
# File 'lib/ninja_model/reflection.rb', line 25

def reflections
  read_inheritable_attribute(:reflections) || write_inheritable_attribute(:reflections, {})
end