Class: Statefully::Change

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

Overview

Change is a tuple of current and previous value of a field in a Diff.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(current:, previous:) ⇒ Change

Constructor for the Statefully::Change object

Examples:

Statefully::Change.new(current: 7, previous: 8)
=> #<Statefully::Change current=7, previous=8>

Parameters:

  • current (Object)

    current State field value

  • previous (Object)

    previous State field value


29
30
31
32
# File 'lib/statefully/change.rb', line 29

def initialize(current:, previous:)
  @current = current
  @previous = previous
end

Instance Attribute Details

#currentObject (readonly)

Returns the current State field value

Examples:

Statefully::Change.new(current: 7, previous: 8).current
=> 7

Returns:

  • (Object)

    current State field value


11
12
13
# File 'lib/statefully/change.rb', line 11

def current
  @current
end

#previousObject (readonly)

Returns the previous State field value

Examples:

Statefully::Change.new(current: 7, previous: 8).previous
=> 8

Returns:

  • (Object)

    previous State field value


20
21
22
# File 'lib/statefully/change.rb', line 20

def previous
  @previous
end

Instance Method Details

#inspectString

Human-readable representation of the Statefully::Change for console inspection

Examples:

Statefully::Change.new(current: 7, previous: 8)
=> #<Statefully::Change current=7, previous=8>

Returns:

  • (String)

47
48
49
50
# File 'lib/statefully/change.rb', line 47

def inspect
  "#<#{self.class.name} " \
  "#{Inspect.from_fields(current: current, previous: previous)}>"
end

#none?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Internal-only method used to determine whether there was any change

Returns:

  • (Boolean)

36
37
38
# File 'lib/statefully/change.rb', line 36

def none?
  @current == @previous
end