Class: Fakery::Change

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

Defined Under Namespace

Modules: Support

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#fromObject (readonly)

Original value from which the field was changed.



13
14
15
# File 'lib/fakery/change.rb', line 13

def from
  @from
end

#nameObject (readonly)

Name of the changed field.



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

def name
  @name
end

#toObject (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.

Returns:

  • (Boolean)


18
19
20
# File 'lib/fakery/change.rb', line 18

def added?
  !!@added
end

#to_sObject 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