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, #serialize_value, #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

#build_value(enum_value_descriptor) ⇒ Object



30
31
32
33
34
35
# File 'lib/protobuf/generators/enum_generator.rb', line 30

def build_value(enum_value_descriptor)
  name = enum_value_descriptor.name
  name.upcase! if ENV.key?('PB_UPCASE_ENUMS')
  number = enum_value_descriptor.number
  "define :#{name}, #{number}"
end

#compileObject



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

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

    print_class(descriptor.name, :enum) do
      if descriptor.options
        print OptionGenerator.new(descriptor.options, current_indent).to_s
        puts
      end

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

    unless descriptor.options.try(:allow_alias)
      self.class.validate_tags(fully_qualified_type_namespace, tags)
    end
  end
end