Class: Sirens::ValueModel
- Inherits:
-
Object
- Object
- Sirens::ValueModel
- Includes:
- Observable
- Defined in:
- lib/models/value_model.rb
Class Method Summary collapse
Instance Method Summary collapse
- #announce_value_changed(new_value:, old_value:) ⇒ Object
-
#initialize(value = nil) ⇒ ValueModel
constructor
Initializing.
- #set_value(new_value) ⇒ Object
-
#value ⇒ Object
Accessing.
Constructor Details
#initialize(value = nil) ⇒ ValueModel
Initializing
15 16 17 18 19 |
# File 'lib/models/value_model.rb', line 15 def initialize(value = nil) super() @value = value end |
Class Method Details
.on(value) ⇒ Object
8 9 10 |
# File 'lib/models/value_model.rb', line 8 def on(value) self.new(value) end |
Instance Method Details
#announce_value_changed(new_value:, old_value:) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/models/value_model.rb', line 37 def announce_value_changed(new_value:, old_value:) changed notify_observers( ValueChanged.new(new_value: new_value, old_value: old_value) ) end |
#set_value(new_value) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/models/value_model.rb', line 27 def set_value(new_value) return if value == new_value old_value = value @value = new_value announce_value_changed(new_value: new_value, old_value: old_value) end |
#value ⇒ Object
Accessing
23 24 25 |
# File 'lib/models/value_model.rb', line 23 def value() @value end |