Class: ActiveFedora::ChangeSet
- Inherits:
-
Object
- Object
- ActiveFedora::ChangeSet
- Defined in:
- lib/active_fedora/change_set.rb
Overview
a Hash of properties that have changed and their present values
Instance Attribute Summary collapse
-
#changed_attributes ⇒ Object
readonly
Returns the value of attribute changed_attributes.
-
#graph ⇒ Object
readonly
Returns the value of attribute graph.
-
#object ⇒ Object
readonly
Returns the value of attribute object.
Instance Method Summary collapse
-
#changes ⇒ Hash<RDF::URI, RDF::Queryable::Enumerator>
Hash of predicate uris to statements.
-
#initialize(object, graph, changed_attributes) ⇒ ChangeSet
constructor
A new instance of ChangeSet.
Constructor Details
#initialize(object, graph, changed_attributes) ⇒ ChangeSet
Returns a new instance of ChangeSet.
9 10 11 12 13 |
# File 'lib/active_fedora/change_set.rb', line 9 def initialize(object, graph, changed_attributes) @object = object @graph = graph @changed_attributes = changed_attributes end |
Instance Attribute Details
#changed_attributes ⇒ Object (readonly)
Returns the value of attribute changed_attributes.
4 5 6 |
# File 'lib/active_fedora/change_set.rb', line 4 def changed_attributes @changed_attributes end |
#graph ⇒ Object (readonly)
Returns the value of attribute graph.
4 5 6 |
# File 'lib/active_fedora/change_set.rb', line 4 def graph @graph end |
#object ⇒ Object (readonly)
Returns the value of attribute object.
4 5 6 |
# File 'lib/active_fedora/change_set.rb', line 4 def object @object end |
Instance Method Details
#changes ⇒ Hash<RDF::URI, RDF::Queryable::Enumerator>
Returns hash of predicate uris to statements.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/active_fedora/change_set.rb', line 18 def changes @changes ||= changed_attributes.each_with_object({}) do |key, result| if object.association(key.to_sym).present? # This is always an ActiveFedora::Reflection::RDFPropertyReflection predicate = object.association(key.to_sym).reflection.predicate result[predicate] = graph.query({ subject: object.rdf_subject, predicate: predicate }) elsif object.class.properties.keys.include?(key) predicate = graph.reflections.reflect_on_property(key).predicate results = graph.query({ subject: object.rdf_subject, predicate: predicate }) new_graph = child_graphs(results.map(&:object)) results.each do |res| new_graph << res end result[predicate] = new_graph elsif key == 'type'.freeze # working around https://github.com/ActiveTriples/ActiveTriples/issues/122 predicate = ::RDF.type result[predicate] = graph.query({ subject: object.rdf_subject, predicate: predicate }) elsif object.local_attributes.include?(key) raise "Unable to find a graph predicate corresponding to the attribute: \"#{key}\"" end end end |