Module: HasVersions::Version::Diff

Defined in:
lib/has_versions/version/diff.rb

Instance Method Summary collapse

Instance Method Details

#applied_modifications(other) ⇒ Object



21
22
23
# File 'lib/has_versions/version/diff.rb', line 21

def applied_modifications(other)
  diff.keys - diff(other).keys
end

#decoded_snapshotObject



29
30
31
32
33
34
35
36
37
# File 'lib/has_versions/version/diff.rb', line 29

def decoded_snapshot
  @decoded_snapshot ||= begin
    decoded = {}
    target.class.versioned_attributes.each do |attribute|
      decoded[attribute] = target.versioning_decode_value(attribute, snapshot[attribute])#attribute.to_s#decode_attribute(attribute, snapshot[attribute])
    end
    decoded
  end
end

#diff(other = parent) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/has_versions/version/diff.rb', line 4

def diff(other = parent)
  diff_fetch(other) do
    other_snapshot = other.nil? ? {} : other.decoded_snapshot

    output = {}
    decoded_snapshot.each do |attribute, new_value|
      other_value = other_snapshot[attribute]

      if other_value != new_value
        output[attribute] = [other_value, new_value]
      end
    end

    output
  end
end

#unused_modifications(other) ⇒ Object



25
26
27
# File 'lib/has_versions/version/diff.rb', line 25

def unused_modifications(other)
  diff.keys & diff(other).keys
end