Module: Miasma::Utils::Immutable
- 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
-
#frozen_valid_state(*args) ⇒ Object
Freezes underlying data hash.
- #save ⇒ Object
Class Method Details
.included(klass) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/miasma/utils/immutable.rb', line 23 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
10 11 12 13 14 15 |
# File 'lib/miasma/utils/immutable.rb', line 10 def frozen_valid_state(*args) unfrozen_valid_state(*args) data.freeze dirty.freeze self end |
#save ⇒ Object
18 19 20 |
# File 'lib/miasma/utils/immutable.rb', line 18 def save raise Error::ImmutableError.new "Resource information cannot be mutated!" end |