Class: Mist::GitModel::Attributes
- Inherits:
-
HashWithIndifferentAccess
- Object
- HashWithIndifferentAccess
- Mist::GitModel::Attributes
- Defined in:
- lib/mist/git_model/attributes.rb
Instance Method Summary collapse
- #[]=(key, value) ⇒ Object
-
#initialize(model) ⇒ Attributes
constructor
A new instance of Attributes.
-
#to_yaml(*args) ⇒ Object
Yamlers using Psych will call this method, we just delegate it into ‘HashWithIndifferentAccess`.
Constructor Details
#initialize(model) ⇒ Attributes
Returns a new instance of Attributes.
2 3 4 5 |
# File 'lib/mist/git_model/attributes.rb', line 2 def initialize(model) @model = model super() end |
Instance Method Details
#[]=(key, value) ⇒ Object
7 8 9 10 |
# File 'lib/mist/git_model/attributes.rb', line 7 def []=(key, value) @model.send(:"#{key}_will_change!") unless !@model || value == self[key] super end |
#to_yaml(*args) ⇒ Object
Yamlers using Psych will call this method, we just delegate it into ‘HashWithIndifferentAccess`. If we don’t, the yaml tag will be “!ruby/object:Mist::GitModel::Attributes” so that when the record is deserialized, this class will be instantiated, resulting in an error. (This class should only be instantiated directly by ‘Mist::GitModel`.)
18 19 20 |
# File 'lib/mist/git_model/attributes.rb', line 18 def to_yaml(*args) HashWithIndifferentAccess.new(self).to_yaml(*args) end |