Class: Interfacets::Shared::GeneratedStore::Handler

Inherits:
Object
  • Object
show all
Defined in:
lib/interfacets/shared/generated_store.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(store:, spec:) ⇒ Handler

Returns a new instance of Handler.



42
43
44
45
# File 'lib/interfacets/shared/generated_store.rb', line 42

def initialize(store:, spec:)
  @store = store
  @spec = spec
end

Instance Attribute Details

#spec ⇒ Object (readonly)

Returns the value of attribute spec.



41
42
43
# File 'lib/interfacets/shared/generated_store.rb', line 41

def spec
  @spec
end

#store ⇒ Object (readonly)

Returns the value of attribute store.



41
42
43
# File 'lib/interfacets/shared/generated_store.rb', line 41

def store
  @store
end

Instance Method Details

#build ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/interfacets/shared/generated_store.rb', line 47

def build
  if spec.type == :reference
    value = spec.klass.new
    store.send("#{spec.name}=", value)
    value
  else
    value = spec.klass.new
    items = store.send(spec.name)
    if items.nil?
      store.send("#{spec.name}=", [value])
    else
      items << value
    end

    value
  end
end