Class: Protobuf::Generators::EnumGenerator

Inherits:
Base
  • Object
show all
Defined in:
lib/protobuf/generators/enum_generator.rb

Constant Summary

Constants included from Printable

Printable::PARENT_CLASS_ENUM, Printable::PARENT_CLASS_MESSAGE, Printable::PARENT_CLASS_SERVICE

Instance Attribute Summary

Attributes inherited from Base

#descriptor, #namespace, #options

Instance Method Summary collapse

Methods inherited from Base

#fully_qualified_type_namespace, #initialize, #run_once, #to_s, #type_namespace, validate_tags

Methods included from Printable

#init_printer

Constructor Details

This class inherits a constructor from Protobuf::Generators::Base

Instance Method Details

#allow_alias?Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/protobuf/generators/enum_generator.rb', line 7

def allow_alias?
  descriptor.options.try(:allow_alias!) { false }
end

#build_value(enum_value_descriptor) ⇒ Object



33
34
35
36
37
# File 'lib/protobuf/generators/enum_generator.rb', line 33

def build_value(enum_value_descriptor)
  name = enum_value_descriptor.name
  number = enum_value_descriptor.number
  return "define :#{name}, #{number}"
end

#compileObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/protobuf/generators/enum_generator.rb', line 11

def compile
  run_once(:compile) do
    tags = []

    print_class(descriptor.name, :enum) do
      if allow_alias?
        puts "set_option :allow_alias"
        puts
      end

      descriptor.value.each do |enum_value_descriptor|
        tags << enum_value_descriptor.number
        puts build_value(enum_value_descriptor)
      end
    end

    unless allow_alias?
      self.class.validate_tags(fully_qualified_type_namespace, tags)
    end
  end
end