module HasVersions::Version::Diff

Public Instance Methods

applied_modifications(other) click to toggle source
# File lib/has_versions/version/diff.rb, line 21
def applied_modifications(other)
  diff.keys - diff(other).keys
end
decoded_snapshot() click to toggle source
# 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.class.versioning_decode_value(attribute, snapshot[attribute])#attribute.to_s#decode_attribute(attribute, snapshot[attribute])
    end
    decoded
  end
end
diff(other = parent) click to toggle source
# 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) click to toggle source
# File lib/has_versions/version/diff.rb, line 25
def unused_modifications(other)
  diff.keys & diff(other).keys
end

Private Instance Methods

diff_fetch(other) { || ... } click to toggle source
# File lib/has_versions/version/diff.rb, line 41
def diff_fetch(other)
  @diff_cache ||= {}
  @diff_cache[other] ||= yield
end