Class: Mist::GitModel::Attributes

Inherits:
HashWithIndifferentAccess
  • Object
show all
Defined in:
lib/mist/git_model/attributes.rb

Instance Method Summary collapse

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