Module: ActiveFedora::SemanticNode::ClassMethods

Defined in:
lib/active_fedora/semantic_node.rb

Instance Method Summary collapse

Instance Method Details

#relationships_descHash

Return hash that persists relationship metadata defined by has_relationship calls. If you implement a child class of ActiveFedora::Base it will inherit the relationship descriptions defined there by merging in the class instance variable values. It will also do this for any level of ancestors.

Examples:

For the following relationship

has_relationship "audio_records", :has_part, :type=>AudioRecord

Results in the following returned by relationships_desc
{:self=>{"audio_records"=>{:type=>AudioRecord, :singular=>nil, :predicate=>:has_part, :inbound=>false}}}


184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/active_fedora/semantic_node.rb', line 184

def relationships_desc
  #get any relationship descriptions from superclasses
  if @class_relationships_desc.nil?
    @class_relationships_desc ||= Hash[:self => {}]

    #get super classes
    super_klasses = []
    #insert in reverse order so the child overwrites anything in parent
    super_klass = self.superclass
    while !super_klass.nil?
      super_klasses.insert(0,super_klass)
      super_klass = super_klass.superclass
    end
  
    super_klasses.each do |super_klass|
      if super_klass.respond_to?(:relationships_desc)
        super_rels = super_klass.relationships_desc
        super_rels.each_pair do |subject,rels|
          @class_relationships_desc[subject] = {} unless @class_relationships_desc.has_key?(subject)
          @class_relationships_desc[subject].merge!(rels)
        end
      end
    end
  end
  @class_relationships_desc
end