class ActiveFedora::ChangeSet

a Hash of properties that have changed and their present values

Attributes

changed_attributes[R]
graph[R]
object[R]

Public Class Methods

new(object, graph, changed_attributes) click to toggle source

@param [ActiveFedora::Base] object The resource that has associations and properties @param [RDF::Graph] graph The RDF graph that holds the current state @param [Array] changed_attributes A list of properties that have changed

# File lib/active_fedora/change_set.rb, line 9
def initialize(object, graph, changed_attributes)
  @object = object
  @graph = graph
  @changed_attributes = changed_attributes
end

Public Instance Methods

changes() click to toggle source

@return [Hash<RDF::URI, RDF::Queryable::Enumerator>] hash of predicate uris to statements

# 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

Private Instance Methods

child_graphs(objects) click to toggle source

@return [RDF::Graph] A graph containing child graphs from changed

attributes.
# File lib/active_fedora/change_set.rb, line 46
def child_graphs(objects)
  child_graphs = ::RDF::Graph.new
  objects.each do |object|
    graph.query({ subject: object }).each do |statement|
      # Have to filter out Fedora triples.
      child_graphs << statement unless FedoraStatement.new(statement).internal?
    end
  end
  child_graphs
end