Module: NRSER::Props::Immutable::InstanceVariables

Defined in:
lib/nrser/props/immutable/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: true

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

Class Methods



24
25
26
27
28
# File 'lib/nrser/props/immutable/instance_variables.rb', line 24

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

Instance Method Details

#initialize_props(values = {}) ⇒ Object

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



37
38
39
40
41
42
43
44
45
46
# File 'lib/nrser/props/immutable/instance_variables.rb', line 37

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