Class: Fakery::Change
- Inherits:
-
Object
- Object
- Fakery::Change
- Defined in:
- lib/fakery/change.rb
Defined Under Namespace
Modules: Support
Instance Attribute Summary collapse
-
#from ⇒ Object
readonly
Original value from which the field was changed.
-
#name ⇒ Object
readonly
Name of the changed field.
-
#to ⇒ Object
readonly
New value to which the field was changed.
Instance Method Summary collapse
-
#added? ⇒ Boolean
Returns true if the field was newly added with this change.
-
#initialize(name:, from:, to:, added: false) ⇒ Change
constructor
name
is the name of the changed field. -
#to_s ⇒ Object
(also: #inspect)
Returns a string representation of this change.
Constructor Details
#initialize(name:, from:, to:, added: false) ⇒ Change
name
is the name of the changed field. from
is the original value from which the field was changed. to
is the new value to which the field was changed. If added
is false (default) this is a change from previously set value, if it’s true then this change is a new addition of a field.
6 7 8 9 |
# File 'lib/fakery/change.rb', line 6 def initialize(name:, from:, to:, added: false) name or raise ArgumentError, 'name keyword argument is required' @name, @from, @to, @added = name, from, to, added end |
Instance Attribute Details
#from ⇒ Object (readonly)
Original value from which the field was changed.
13 14 15 |
# File 'lib/fakery/change.rb', line 13 def from @from end |
#name ⇒ Object (readonly)
Name of the changed field.
11 12 13 |
# File 'lib/fakery/change.rb', line 11 def name @name end |
#to ⇒ Object (readonly)
New value to which the field was changed.
15 16 17 |
# File 'lib/fakery/change.rb', line 15 def to @to end |
Instance Method Details
#added? ⇒ Boolean
Returns true if the field was newly added with this change.
18 19 20 |
# File 'lib/fakery/change.rb', line 18 def added? !!@added end |
#to_s ⇒ Object Also known as: inspect
Returns a string representation of this change. A change from=nil* is an addition change as opposed to a regular change from some previous value.
24 25 26 |
# File 'lib/fakery/change.rb', line 24 def to_s "<#{self.class} name=#{@name.inspect} from=#{@from.inspect}#{?* if @added} to=#{@to.inspect}>" end |