class Pedanco::Diffr::Change

A Change represents a current and previous state for specifc piece of data. These states can represent any kind of information and are linked by the name of the data they represent.

Pedanco::Diffr::Change.new(:first_name, 'Jim', 'James')

@!attribute [rw] name

@return [String,Symbol] the name identifier for the change set

@!attribute [rw] current

@return [Any] the current state of the change

@!attribute [rw] previous

@return [Any] the previous state of the change

@author [jpolanco]

Attributes

current[RW]
name[RW]
previous[RW]

Public Class Methods

new(name, current = nil, previous = nil) click to toggle source

Initializes the data when passed via new().

@param name [String/Symbol] (required) The name of the data @param current [Any] (optional) The current value for the

change, defaults to nil.

@param previous [Any] (optional) The previous value for the

change, defaults to nil.

@raise [RuntimeError] if name is nil or ''

# File lib/pedanco/diffr/change.rb, line 32
def initialize(name, current = nil, previous = nil)
  fail 'Name is required for a Change.' if name.blank?
  @name     = name
  @current  = current
  @previous = previous
end

Public Instance Methods

to_a() click to toggle source

Converts the Change into an array, following the ActiveRecord changes syntax. The first position is the previous value, the second is the current value.

@return [Array] The array version of the Change

# File lib/pedanco/diffr/change.rb, line 45
def to_a
  [@previous, @current]
end