Module: Miasma::Utils::Immutable

Included in:
Models::Orchestration::Stack::Event, Models::Orchestration::Stack::Resource
Defined in:
lib/miasma/utils/immutable.rb

Overview

Note:

this should be included at end of model definition

Make best effort to make model immutable

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



25
26
27
28
29
30
# File 'lib/miasma/utils/immutable.rb', line 25

def included(klass)
  klass.class_eval do
    alias_method :unfrozen_valid_state, :valid_state
    alias_method :valid_state, :frozen_valid_state
  end
end

Instance Method Details

#frozen_valid_state(*args) ⇒ Object

Freezes underlying data hash



11
12
13
14
15
16
# File 'lib/miasma/utils/immutable.rb', line 11

def frozen_valid_state(*args)
  unfrozen_valid_state(*args)
  data.freeze
  dirty.freeze
  self
end

#saveObject



19
20
21
# File 'lib/miasma/utils/immutable.rb', line 19

def save
  raise Error::ImmutableError.new 'Resource information cannot be mutated!'
end