class ActiveFedora::ChangeSet

a Hash of properties that have changed and their present values

def changes

Returns:
  • (Hash) - hash of predicate uris to statements
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

def child_graphs(objects)

Returns:
  • (RDF::Graph) - A graph containing child graphs from changed
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

def initialize(object, graph, changed_attributes)

Parameters:
  • changed_attributes (Array) -- A list of properties that have changed
  • graph (RDF::Graph) -- The RDF graph that holds the current state
  • object (ActiveFedora::Base) -- The resource that has associations and properties
def initialize(object, graph, changed_attributes)
  @object = object
  @graph = graph
  @changed_attributes = changed_attributes
end