-
Notifications
You must be signed in to change notification settings - Fork 63
/
rdf_datastream_attribute.rb
47 lines (42 loc) · 1.14 KB
/
rdf_datastream_attribute.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
module ActiveFedora
# Class for attributes that are delegated to a RDFDatastream
class RdfDatastreamAttribute < StreamAttribute
# @param [ActiveFedora::Base] obj the object that has the attribute
# @param [Object] v value to write to the attribute
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
# @param [ActiveFedora::Base] obj the object that has the attribute
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
end
end