Sha256: 240051fe2e7893f3797d0fc320757c8ae3e9b785d6ec471b271915745e9657e4

Contents?: true

Size: 1.23 KB

Versions: 16

Compression:

Stored size: 1.23 KB

Contents

module ActiveFedora
  # a Hash of properties that have changed and their present values
  class ChangeSet

    attr_reader :object, :graph, :changed_attributes

    # @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
    def initialize(object, graph, changed_attributes)
      @object = object
      @graph = graph
      @changed_attributes = changed_attributes
    end

    def empty?
      changes.empty?
    end

    def changes
      @changes ||= changed_attributes.each_with_object({}) do |key, result|
        if m = /^.*_ids?$/.match(key)
          predicate = object.association(m[0].to_sym).reflection.predicate
          result[predicate] = graph.query(predicate: predicate)
        elsif object.class.properties.keys.include?(key)
          predicate = graph.reflections.reflect_on_property(key).predicate
          result[predicate] = graph.query(predicate: predicate)
        elsif object.local_attributes.include?(key)
          raise "Unable to find a graph predicate corresponding to the attribute: \"#{key}\""
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
active-fedora-9.0.4 lib/active_fedora/change_set.rb
active-fedora-9.0.3 lib/active_fedora/change_set.rb
active-fedora-9.0.2 lib/active_fedora/change_set.rb
active-fedora-9.0.1 lib/active_fedora/change_set.rb
active-fedora-9.0.0 lib/active_fedora/change_set.rb
active-fedora-9.0.0.rc3 lib/active_fedora/change_set.rb
active-fedora-9.0.0.rc2 lib/active_fedora/change_set.rb
active-fedora-9.0.0.rc1 lib/active_fedora/change_set.rb
active-fedora-9.0.0.beta8 lib/active_fedora/change_set.rb
active-fedora-9.0.0.beta7 lib/active_fedora/change_set.rb
active-fedora-9.0.0.beta6 lib/active_fedora/change_set.rb
active-fedora-9.0.0.beta5 lib/active_fedora/change_set.rb
active-fedora-9.0.0.beta4 lib/active_fedora/change_set.rb
active-fedora-9.0.0.beta3 lib/active_fedora/change_set.rb
active-fedora-9.0.0.beta2 lib/active_fedora/change_set.rb
active-fedora-9.0.0.beta1 lib/active_fedora/change_set.rb