Module: Kind::ImmutableAttributes::Initializer

Included in:
Action
Defined in:
lib/kind/immutable_attributes/initializer.rb

Instance Method Summary collapse

Instance Method Details

#initialize(arg) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/kind/immutable_attributes/initializer.rb', line 10

def initialize(arg)
  input = __resolve_attribute_input(arg)

  hash = call_before_initialize_to_prepare_the_input(input)

  @_nil_attrs = ::Set.new
  @_____attrs = {}
  @attributes = {}

  self.class.__attributes__.each do |name, (kind, default, visibility)|
    value_to_assign = __resolve_attribute_value_to_assign(kind, default, hash, name)

    @_nil_attrs << name if value_to_assign.nil?
    @_____attrs[name] = value_to_assign
    @attributes[name] = value_to_assign if visibility == :public

    instance_variable_set("@#{name}", value_to_assign)
  end

  @_nil_attrs.freeze
  @attributes.freeze

  call_after_initialize_and_assign_the_attributes
end

#nil_attributesObject



35
36
37
# File 'lib/kind/immutable_attributes/initializer.rb', line 35

def nil_attributes
  @_nil_attrs.to_a
end

#nil_attributes?(*names) ⇒ Boolean

Returns:



39
40
41
# File 'lib/kind/immutable_attributes/initializer.rb', line 39

def nil_attributes?(*names)
  names.empty? ? !@_nil_attrs.empty? : names.all? { |name| @_nil_attrs.include?(name) }
end