Class: GoonModelGen::Source::Enum

Inherits:
Type
  • Object
show all
Defined in:
lib/goon_model_gen/source/enum.rb

Defined Under Namespace

Classes: Element

Instance Attribute Summary collapse

Attributes inherited from Type

#file, #generators, #name

Attributes included from Contextual

#context

Instance Method Summary collapse

Constructor Details

#initialize(name, base_type, element_definitions) ⇒ Enum

Returns a new instance of Enum.

Parameters:

  • name (String)
  • base_type (String)
  • element_definitions (Array<Hash<Object,String>>, Hash<Object,String>)


21
22
23
24
25
26
27
28
29
30
# File 'lib/goon_model_gen/source/enum.rb', line 21

def initialize(name, base_type, element_definitions)
  unless element_definitions.all?{|i| i.is_a?(Hash) && (i.length == 1) }
    raise "Enum element definitions must be an Array of 1 element Hash but was #{element_definitions.inspect}"
  end
  super(name)
  @base_type = base_type
  @elements = element_definitions.map do |i|
    Element.new(i.keys.first, i.values.first)
  end
end

Instance Attribute Details

#base_typeObject (readonly)

Returns the value of attribute base_type.



16
17
18
# File 'lib/goon_model_gen/source/enum.rb', line 16

def base_type
  @base_type
end

#elementsObject (readonly)

Returns the value of attribute elements.



16
17
18
# File 'lib/goon_model_gen/source/enum.rb', line 16

def elements
  @elements
end