Class: PollEverywhere::Serializable::Property::Value

Inherits:
Object
  • Object
show all
Defined in:
lib/polleverywhere/serializable.rb

Overview

Contains the value of the property, runs validations, and tracks property changes

Defined Under Namespace

Classes: Set

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(property) ⇒ Value

Returns a new instance of Value.



107
108
109
# File 'lib/polleverywhere/serializable.rb', line 107

def initialize(property)
  @property = property
end

Instance Attribute Details

#currentObject Also known as: is

Returns the value of attribute current.



102
103
104
# File 'lib/polleverywhere/serializable.rb', line 102

def current
  @current
end

#originalObject (readonly) Also known as: was

Returns the value of attribute original.



101
102
103
# File 'lib/polleverywhere/serializable.rb', line 101

def original
  @original
end

#propertyObject (readonly)

Returns the value of attribute property.



101
102
103
# File 'lib/polleverywhere/serializable.rb', line 101

def property
  @property
end

Instance Method Details

#changed?Boolean

Detect if the values have changed since we last updated them

Returns:

  • (Boolean)


112
113
114
# File 'lib/polleverywhere/serializable.rb', line 112

def changed?
  original != current
end

#changesObject

The original and current state of the value if it changed.



117
118
119
# File 'lib/polleverywhere/serializable.rb', line 117

def changes
  [original, current] if changed?
end

#commitObject

Commit the values if they’re valid



122
123
124
# File 'lib/polleverywhere/serializable.rb', line 122

def commit
  @original = @current
end