Module: NRSER::Props::Immutable::HashVariable
- Included in:
- Base
- Defined in:
- lib/nrser/props/immutable/hash_variable.rb
Overview
Mix-in to store property values in an immutable Hamster::Hash instance in an instance variable.
This is basically an improvement of how the original props implementation worked.
Defined Under Namespace
Classes: Base
Constant Summary collapse
- KEY_STORAGE =
NRSER::Props::Storage::Key.new immutable: true, key_type: :name
- INSTANCE_VARIABLE_STORAGE =
NRSER::Props::Storage::InstanceVariable.new sub_storage: KEY_STORAGE
Class Method Summary collapse
-
.included(base) ⇒ Object
Class Methods ======================================================================.
Instance Method Summary collapse
-
#initialize_props(values = {}) ⇒ Object
Instantiate a new ‘NRSER::Props::Immutable::Vector`.
Class Method Details
.included(base) ⇒ Object
Class Methods
43 44 45 46 47 |
# File 'lib/nrser/props/immutable/hash_variable.rb', line 43 def self.included base base.include NRSER::Props base..storage INSTANCE_VARIABLE_STORAGE base..freeze end |
Instance Method Details
#initialize_props(values = {}) ⇒ Object
Instantiate a new ‘NRSER::Props::Immutable::Vector`.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/nrser/props/immutable/hash_variable.rb', line 54 def initialize_props values = {} prop_values = {} self.class..each_primary_prop_value_from( values ) { |prop, value| prop_values[prop.name] = value } instance_variable_set self.class..storage.var_name, Hamster::Hash.new( values ) # Check additional type invariants self.class.invariants.each do |type| type.check self end end |