Class: SmoothOperator::Attributes::Dirty

Inherits:
Object
  • Object
show all
Defined in:
lib/smooth_operator/attributes/dirty.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, value, type, unknown_hash_class) ⇒ Dirty



10
11
12
13
14
# File 'lib/smooth_operator/attributes/dirty.rb', line 10

def initialize(name, value, type, unknown_hash_class)
  @original_name, @original_value, @type, @unknown_hash_class = name, value, type, unknown_hash_class

  @first_value = set_value(value)
end

Instance Attribute Details

#first_valueObject (readonly)

Returns the value of attribute first_value.



8
9
10
# File 'lib/smooth_operator/attributes/dirty.rb', line 8

def first_value
  @first_value
end

#original_nameObject (readonly)

Returns the value of attribute original_name.



8
9
10
# File 'lib/smooth_operator/attributes/dirty.rb', line 8

def original_name
  @original_name
end

#original_valueObject (readonly)

Returns the value of attribute original_value.



8
9
10
# File 'lib/smooth_operator/attributes/dirty.rb', line 8

def original_value
  @original_value
end

#typeObject (readonly)

Returns the value of attribute type.



8
9
10
# File 'lib/smooth_operator/attributes/dirty.rb', line 8

def type
  @type
end

#unknown_hash_classObject (readonly)

Returns the value of attribute unknown_hash_class.



8
9
10
# File 'lib/smooth_operator/attributes/dirty.rb', line 8

def unknown_hash_class
  @unknown_hash_class
end

#valueObject (readonly)

Returns the value of attribute value.



8
9
10
# File 'lib/smooth_operator/attributes/dirty.rb', line 8

def value
  @value
end

Instance Method Details

#changed?Boolean



20
21
22
# File 'lib/smooth_operator/attributes/dirty.rb', line 20

def changed?
  @first_value != @value
end

#set_value(new_value) ⇒ Object



16
17
18
# File 'lib/smooth_operator/attributes/dirty.rb', line 16

def set_value(new_value)
  @value = TypeConverter.cast_to_type(original_name, new_value, type, self.class, unknown_hash_class)
end

#wasObject



24
25
26
# File 'lib/smooth_operator/attributes/dirty.rb', line 24

def was
  @first_value
end