Module: ActiveFedora::Reflection::ClassMethods

Defined in:
lib/active_fedora/reflection.rb

Defined Under Namespace

Classes: AssociationReflection, MacroReflection

Instance Method Summary collapse

Instance Method Details

#create_reflection(macro, name, options, active_fedora) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/active_fedora/reflection.rb', line 13

def create_reflection(macro, name, options, active_fedora)
  case macro
    when :has_many, :belongs_to, :has_and_belongs_to_many
      klass = AssociationReflection
      reflection = klass.new(macro, name, options, active_fedora)
  end

  self.reflections = self.reflections.merge(name => reflection)
  reflection
end

#reflect_on_association(association) ⇒ Object

Returns the AssociationReflection object for the association (use the symbol).

Account.reflect_on_association(:owner)             # returns the owner AssociationReflection
Invoice.reflect_on_association(:line_items).macro  # returns :has_many


39
40
41
# File 'lib/active_fedora/reflection.rb', line 39

def reflect_on_association(association)
  reflections[association].is_a?(AssociationReflection) ? reflections[association] : nil
end

#reflectionsObject

Returns a hash containing all AssociationReflection objects for the current class. Example:

Invoice.reflections
Account.reflections


30
31
32
# File 'lib/active_fedora/reflection.rb', line 30

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