Module: ActiveFedora::Reflection::ClassMethods
- Defined in:
- lib/active_fedora/reflection.rb
Defined Under Namespace
Classes: AssociationReflection, MacroReflection
Instance Method Summary collapse
- #create_reflection(macro, name, options, active_fedora) ⇒ Object
-
#reflect_on_association(association) ⇒ Object
Returns the AssociationReflection object for the
association
(use the symbol). - #reflection_name_for_predicate(predicate) ⇒ Object
-
#reflections ⇒ Object
Returns a hash containing all AssociationReflection objects for the current class.
Instance Method Details
#create_reflection(macro, name, options, active_fedora) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/active_fedora/reflection.rb', line 17 def create_reflection(macro, name, , active_fedora) case macro when :has_many, :belongs_to, :has_and_belongs_to_many klass = AssociationReflection reflection = klass.new(macro, name, , 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
43 44 45 |
# File 'lib/active_fedora/reflection.rb', line 43 def reflect_on_association(association) reflections[association].is_a?(AssociationReflection) ? reflections[association] : nil end |
#reflection_name_for_predicate(predicate) ⇒ Object
11 12 13 14 15 |
# File 'lib/active_fedora/reflection.rb', line 11 def reflection_name_for_predicate(predicate) reflections.each do |k, v| return k if v.[:property] == predicate end end |
#reflections ⇒ Object
Returns a hash containing all AssociationReflection objects for the current class. Example:
Invoice.reflections
Account.reflections
34 35 36 |
# File 'lib/active_fedora/reflection.rb', line 34 def reflections read_inheritable_attribute(:reflections) || write_inheritable_attribute(:reflections, {}) end |