Class: GoonModelGen::Golang::Enum

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

Defined Under Namespace

Classes: Element

Instance Attribute Summary collapse

Attributes inherited from Type

#name, #package

Instance Method Summary collapse

Methods inherited from Type

#memo, #qualified_name

Constructor Details

#initialize(name, base_type_name) ⇒ Enum

Returns a new instance of Enum.

Parameters:

  • name (String)
  • base_type_name (String)


20
21
22
23
24
# File 'lib/goon_model_gen/golang/enum.rb', line 20

def initialize(name, base_type_name)
  super(name)
  @base_type_name = base_type_name
  @elements = []
end

Instance Attribute Details

#base_typeObject (readonly)

Returns the value of attribute base_type.



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

def base_type
  @base_type
end

#base_type_nameObject (readonly)

Returns the value of attribute base_type_name.



15
16
17
# File 'lib/goon_model_gen/golang/enum.rb', line 15

def base_type_name
  @base_type_name
end

#elementsObject (readonly)

Returns the value of attribute elements.



15
16
17
# File 'lib/goon_model_gen/golang/enum.rb', line 15

def elements
  @elements
end

Instance Method Details

#add(value, name) ⇒ Object

Parameters:

  • value (Object)
  • name (String)


28
29
30
# File 'lib/goon_model_gen/golang/enum.rb', line 28

def add(value, name)
  elements << Element.new(value, name)
end

#each_value_and_name {|value, name| ... } ⇒ Object

Yield Parameters:

  • value (Object)
  • name (String)


34
35
36
37
38
# File 'lib/goon_model_gen/golang/enum.rb', line 34

def each_value_and_name
  elements.each do |i|
    yield(i.value, i.name)
  end
end

#resolve(pkgs) ⇒ Object

Parameters:



41
42
43
# File 'lib/goon_model_gen/golang/enum.rb', line 41

def resolve(pkgs)
  @base_type = pkgs.type_for(base_type_name) || raise("#{base_type_name.inspect} not found for #{name}")
end