Sha256: 51dcff1038c15282618272fee462d7dd232ae34d07d5d7635aa9d1c99f866a43

Contents?: true

Size: 694 Bytes

Versions: 4

Compression:

Stored size: 694 Bytes

Contents

class Mist::GitModel::Attributes < HashWithIndifferentAccess
  def initialize(model)
    @model = model
    super()
  end
  
  def []=(key, value)
    @model.send(:"#{key}_will_change!") unless !@model || value == self[key]
    super
  end
  
  # 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`.)
  def to_yaml(*args)
    HashWithIndifferentAccess.new(self).to_yaml(*args)
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
mist-0.6.3 lib/mist/git_model/attributes.rb
mist-0.6.2 lib/mist/git_model/attributes.rb
mist-0.6.1 lib/mist/git_model/attributes.rb
mist-0.6.0 lib/mist/git_model/attributes.rb