Class: Pedanco::Diffr::Change

Inherits:
Object
  • Object
show all
Defined in:
lib/pedanco/diffr/change.rb

Overview

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')

Author:

  • jpolanco

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, current = nil, previous = nil) ⇒ Change

Initializes the data when passed via new().

Parameters:

  • name (String/Symbol)

    (required) The name of the data

  • current (Any) (defaults to: nil)

    (optional) The current value for the change, defaults to nil.

  • previous (Any) (defaults to: nil)

    (optional) The previous value for the change, defaults to nil.

Raises:

  • (RuntimeError)

    if name is nil or ”



32
33
34
35
36
37
# 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

Instance Attribute Details

#currentAny

Returns the current state of the change.

Returns:

  • (Any)

    the current state of the change



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/pedanco/diffr/change.rb', line 19

class Change
  attr_accessor :name, :current, :previous

  #
  # 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 ''
  def initialize(name, current = nil, previous = nil)
    fail 'Name is required for a Change.' if name.blank?
    @name     = name
    @current  = current
    @previous = previous
  end

  #
  # 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
  def to_a
    [@previous, @current]
  end
end

#nameString, Symbol

Returns the name identifier for the change set.

Returns:

  • (String, Symbol)

    the name identifier for the change set



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/pedanco/diffr/change.rb', line 19

class Change
  attr_accessor :name, :current, :previous

  #
  # 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 ''
  def initialize(name, current = nil, previous = nil)
    fail 'Name is required for a Change.' if name.blank?
    @name     = name
    @current  = current
    @previous = previous
  end

  #
  # 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
  def to_a
    [@previous, @current]
  end
end

#previousAny

Returns the previous state of the change.

Returns:

  • (Any)

    the previous state of the change



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/pedanco/diffr/change.rb', line 19

class Change
  attr_accessor :name, :current, :previous

  #
  # 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 ''
  def initialize(name, current = nil, previous = nil)
    fail 'Name is required for a Change.' if name.blank?
    @name     = name
    @current  = current
    @previous = previous
  end

  #
  # 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
  def to_a
    [@previous, @current]
  end
end

Instance Method Details

#to_aArray

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

Returns:

  • (Array)

    The array version of the Change



45
46
47
# File 'lib/pedanco/diffr/change.rb', line 45

def to_a
  [@previous, @current]
end