Class: ActiveFedora::RdfNode::TermProxy
- Inherits:
-
Object
- Object
- ActiveFedora::RdfNode::TermProxy
- Defined in:
- lib/active_fedora/rdf_node/term_proxy.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#predicate ⇒ Object
readonly
Returns the value of attribute predicate.
-
#subject ⇒ Object
readonly
Returns the value of attribute subject.
Instance Method Summary collapse
- #<<(*values) ⇒ Object
- #build(attributes = nil) ⇒ Object
- #delete(*values) ⇒ Object
-
#initialize(parent, subject, predicate, options) ⇒ TermProxy
constructor
A new instance of TermProxy.
- #load_values ⇒ Object
- #mint_node(attributes = nil) ⇒ Object
- #reset! ⇒ Object
- #target ⇒ Object
Constructor Details
#initialize(parent, subject, predicate, options) ⇒ TermProxy
Returns a new instance of TermProxy.
12 13 14 15 16 17 |
# File 'lib/active_fedora/rdf_node/term_proxy.rb', line 12 def initialize(parent, subject, predicate, ) @parent = parent @subject = subject @predicate = predicate @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/active_fedora/rdf_node/term_proxy.rb', line 5 def @options end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
5 6 7 |
# File 'lib/active_fedora/rdf_node/term_proxy.rb', line 5 def parent @parent end |
#predicate ⇒ Object (readonly)
Returns the value of attribute predicate.
5 6 7 |
# File 'lib/active_fedora/rdf_node/term_proxy.rb', line 5 def predicate @predicate end |
#subject ⇒ Object (readonly)
Returns the value of attribute subject.
5 6 7 |
# File 'lib/active_fedora/rdf_node/term_proxy.rb', line 5 def subject @subject end |
Instance Method Details
#<<(*values) ⇒ Object
40 41 42 43 44 |
# File 'lib/active_fedora/rdf_node/term_proxy.rb', line 40 def <<(*values) values.each { |value| parent.append(subject, predicate, value) } reset! values end |
#build(attributes = nil) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/active_fedora/rdf_node/term_proxy.rb', line 20 def build(attributes=nil) node = mint_node(attributes) parent.graph.insert([subject, predicate, node.rdf_subject]) reset! new_node = target.find { |n| n.rdf_subject == node.rdf_subject} new_node.new_record = true new_node end |
#delete(*values) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/active_fedora/rdf_node/term_proxy.rb', line 46 def delete(*values) values.each do |value| parent.delete_predicate(subject, predicate, value) end values end |
#load_values ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/active_fedora/rdf_node/term_proxy.rb', line 58 def load_values values = [] parent.query(subject, predicate).each do |solution| v = solution.value v = v.to_s if v.is_a? RDF::Literal if [:type] == :date v = Date.parse(v) end # If the user provided options[:class_name], we should query to make sure this # potential solution is of the right RDF.type if [:class_name] klass = class_from_rdf_type(v) values << v if klass == ActiveFedora.class_from_string([:class_name], parent.class) else values << v end end if [:class_name] values = values.map{ |found_subject| class_from_rdf_type(found_subject).new(parent.graph, found_subject)} end values end |
#mint_node(attributes = nil) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/active_fedora/rdf_node/term_proxy.rb', line 33 def mint_node(attributes=nil) new_subject = RDF::Node.new return parent.target_class(predicate).new(parent.graph, new_subject).tap do |node| node.attributes = attributes if attributes end end |
#reset! ⇒ Object
29 30 31 |
# File 'lib/active_fedora/rdf_node/term_proxy.rb', line 29 def reset! @target = nil end |
#target ⇒ Object
54 55 56 |
# File 'lib/active_fedora/rdf_node/term_proxy.rb', line 54 def target @target ||= load_values end |