Class: ActiveFedora::RdfDatastreamAttribute

Inherits:
StreamAttribute show all
Defined in:
lib/active_fedora/attributes/rdf_datastream_attribute.rb

Overview

Class for attributes that are delegated to a RDFDatastream

Instance Attribute Summary

Attributes inherited from StreamAttribute

#at, #delegate_target, #target_class

Attributes inherited from DelegatedAttribute

#field, #multiple

Instance Method Summary collapse

Methods inherited from StreamAttribute

#initialize, #primary_solr_name, #type

Methods inherited from DelegatedAttribute

#initialize

Constructor Details

This class inherits a constructor from ActiveFedora::StreamAttribute

Instance Method Details

#reader(obj) ⇒ Object

Parameters:



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/active_fedora/attributes/rdf_datastream_attribute.rb', line 25

def reader(obj)
  node = file_for_attribute(obj, delegate_target)
  term = if at
           vals = at.dup
           while vals.length > 1
             node = node.send(vals.shift)
             node = if node.empty?
                      node.build
                    else
                      node.first
                    end
           end
           vals.first
         else
           field
         end
  node.send(term)
end

#writer(obj, v) ⇒ Object

Parameters:

  • obj (ActiveFedora::Base)

    the object that has the attribute

  • v (Object)

    value to write to the attribute



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/active_fedora/attributes/rdf_datastream_attribute.rb', line 7

def writer(obj, v)
  node = file_for_attribute(obj, delegate_target)
  obj.mark_as_changed(field) if obj.value_has_changed?(field, v)
  term = if at
           vals = at.dup
           while vals.length > 1
             node = node.send(vals.shift)
             node = node.build if node.empty?
             node = node.first
           end
           vals.first
         else
           field
         end
  node.send("#{term}=", v)
end