Module: NRSER::Props::Mutable::InstanceVariables

Defined in:
lib/nrser/props/mutable/instance_variables.rb

Overview

Mix-in to store property values in instance variables of the same name.

Constant Summary collapse

STORAGE =
NRSER::Props::Storage::InstanceVariables.new immutable: false

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

Class Methods



36
37
38
39
40
# File 'lib/nrser/props/mutable/instance_variables.rb', line 36

def self.included base
  base.include NRSER::Props
  base..storage STORAGE
  base..freeze
end

Instance Method Details

#initialize_props(values = {}) ⇒ Object

Since the Immutable::InstanceVariables mix-in does not need to tap into the initialize chain,



49
50
51
52
53
54
55
56
57
58
# File 'lib/nrser/props/mutable/instance_variables.rb', line 49

def initialize_props values = {}
  self.class..each_primary_prop_value_from( values ) { |prop, value|
    instance_variable_set "@#{ prop.name }", value
  }
  
  # Check additional type invariants
  self.class.invariants.each do |type|
    type.check self
  end
end