class Recorder::Changeset

Attributes

changes[R]
item[R]

Public Class Methods

new(item, changes) click to toggle source
# File lib/recorder/changeset.rb, line 7
def initialize(item, changes)
  @item = item
  @changes = changes.to_h
end

Public Instance Methods

human_attribute_name(attribute) click to toggle source
# File lib/recorder/changeset.rb, line 16
def human_attribute_name(attribute)
  if defined?(Draper) && item.decorated?
    item.source.class.human_attribute_name(attribute.to_s)
  else
    item.class.human_attribute_name(attribute.to_s)
  end
end
keys() click to toggle source
# File lib/recorder/changeset.rb, line 12
def keys
  changes.try(:keys) || []
end
next(attribute) click to toggle source
# File lib/recorder/changeset.rb, line 40
def next(attribute)
  try("next_#{attribute}") || next_version.try(attribute)
end
next_version() click to toggle source
# File lib/recorder/changeset.rb, line 44
def next_version
  return @next_version if defined?(@next_version)

  @next_version = item.dup

  changes.each do |key, change|
    @next_version.send("#{key}=", change[1])
  end

  @next_version
end
previous(attribute) click to toggle source
# File lib/recorder/changeset.rb, line 24
def previous(attribute)
  try("previous_#{attribute}") || previous_version.try(attribute)
end
previous_version() click to toggle source
# File lib/recorder/changeset.rb, line 28
def previous_version
  return @previous_version if defined?(@previous_version)

  @previous_version = item.dup

  changes.each do |key, change|
    @previous_version.send("#{key}=", change[0])
  end

  @previous_version
end