Module: ActiveFedora::Reflection::ClassMethods
- Defined in:
- lib/active_fedora/reflection.rb
Instance Method Summary collapse
- #add_reflection(name, reflection) ⇒ Object
- #child_resource_reflections ⇒ Object
- #contained_rdf_source_reflections ⇒ Object
- #create_reflection(macro, name, options, active_fedora) ⇒ Object
- #outgoing_reflections ⇒ Object
- #reflect_on_all_autosave_associations ⇒ Object
-
#reflect_on_association(association) ⇒ Object
Returns the AssociationReflection object for the
association
(use the symbol). -
#reflections ⇒ Object
Returns a hash containing all AssociationReflection objects for the current class.
Instance Method Details
#add_reflection(name, reflection) ⇒ Object
24 25 26 27 |
# File 'lib/active_fedora/reflection.rb', line 24 def add_reflection(name, reflection) # FIXME: this is where the problem with association_spec is caused (key is string now) self.reflections = reflections.merge(name => reflection) end |
#child_resource_reflections ⇒ Object
43 44 45 |
# File 'lib/active_fedora/reflection.rb', line 43 def child_resource_reflections reflections.select { |_, reflection| reflection.is_a?(AssociationReflection) && reflection.macro == :contains && reflection.klass <= ActiveFedora::File } end |
#contained_rdf_source_reflections ⇒ Object
47 48 49 |
# File 'lib/active_fedora/reflection.rb', line 47 def contained_rdf_source_reflections reflections.select { |_, reflection| reflection.is_a?(AssociationReflection) && reflection.macro == :contains && !(reflection.klass <= ActiveFedora::File) } end |
#create_reflection(macro, name, options, active_fedora) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/active_fedora/reflection.rb', line 11 def create_reflection(macro, name, , active_fedora) klass = case macro when :has_many, :belongs_to, :has_and_belongs_to_many, :contains, :directly_contains, :directly_contains_one, :indirectly_contains AssociationReflection when :rdf, :singular_rdf RDFPropertyReflection end reflection = klass.new(macro, name, , active_fedora) add_reflection name, reflection reflection end |
#outgoing_reflections ⇒ Object
39 40 41 |
# File 'lib/active_fedora/reflection.rb', line 39 def outgoing_reflections reflections.select { |_, reflection| reflection.is_a? RDFPropertyReflection } end |
#reflect_on_all_autosave_associations ⇒ Object
66 67 68 |
# File 'lib/active_fedora/reflection.rb', line 66 def reflect_on_all_autosave_associations reflections.values.select { |reflection| reflection.[:autosave] } 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
56 57 58 59 60 61 62 63 64 |
# File 'lib/active_fedora/reflection.rb', line 56 def reflect_on_association(association) val = reflections[association].is_a?(AssociationReflection) ? reflections[association] : nil unless val # When a has_many is paired with a has_and_belongs_to_many the assocation will have a plural name association = association.to_s.pluralize.to_sym val = reflections[association].is_a?(AssociationReflection) ? reflections[association] : nil end val end |
#reflections ⇒ Object
Returns a hash containing all AssociationReflection objects for the current class. Example:
Invoice.reflections
Account.reflections
35 36 37 |
# File 'lib/active_fedora/reflection.rb', line 35 def reflections read_inheritable_attribute(:reflections) || write_inheritable_attribute(:reflections, {}) end |