Class: OAPI::Types::Map

Inherits:
Object
  • Object
show all
Defined in:
lib/oapi/types/map.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(store = {}) ⇒ Map

Returns a new instance of Map.



6
7
8
9
# File 'lib/oapi/types/map.rb', line 6

def initialize(store = {}, &)
  @store = store
  super(&)
end

Class Attribute Details

.item_nameObject (readonly)

Returns the value of attribute item_name.



12
13
14
# File 'lib/oapi/types/map.rb', line 12

def item_name
  @item_name
end

.item_typeObject (readonly)

Returns the value of attribute item_type.



12
13
14
# File 'lib/oapi/types/map.rb', line 12

def item_type
  @item_type
end

Instance Attribute Details

#storeObject (readonly)

Returns the value of attribute store.



4
5
6
# File 'lib/oapi/types/map.rb', line 4

def store
  @store
end

Class Method Details

.item(name, type = nil) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/oapi/types/map.rb', line 14

def item(name, type = nil)
  @item_name = name
  @item_type = type

  define_method(name) do |key, ref: nil, &block|
    raise ArgumentError, "'#{key}' already exists" if @store.include?(key.to_s)

    raise ArgumentError, "ref and block are mutual exclusive" if ref && block

    return @store[key] = OAPI::Ref.new(ref) if ref

    @store[key] = type.new(&block)
  end
end