Class: ActiveFedora::ChangeSet

Inherits:
Object
  • Object
show all
Defined in:
lib/active_fedora/change_set.rb

Overview

a Hash of properties that have changed and their present values

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, graph, changed_attributes) ⇒ ChangeSet


10
11
12
13
14
# File 'lib/active_fedora/change_set.rb', line 10

def initialize(object, graph, changed_attributes)
  @object = object
  @graph = graph
  @changed_attributes = changed_attributes
end

Instance Attribute Details

#changed_attributesObject (readonly)

Returns the value of attribute changed_attributes


5
6
7
# File 'lib/active_fedora/change_set.rb', line 5

def changed_attributes
  @changed_attributes
end

#graphObject (readonly)

Returns the value of attribute graph


5
6
7
# File 'lib/active_fedora/change_set.rb', line 5

def graph
  @graph
end

#objectObject (readonly)

Returns the value of attribute object


5
6
7
# File 'lib/active_fedora/change_set.rb', line 5

def object
  @object
end

Instance Method Details

#changesObject


20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/active_fedora/change_set.rb', line 20

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

#empty?Boolean


16
17
18
# File 'lib/active_fedora/change_set.rb', line 16

def empty?
  changes.empty?
end