Class: Protobuf::Descriptor::EnumDescriptor

Inherits:
Object
  • Object
show all
Defined in:
lib/protobuf/descriptor/enum_descriptor.rb

Instance Method Summary collapse

Constructor Details

#initialize(enum_class) ⇒ EnumDescriptor

Returns a new instance of EnumDescriptor.



4
5
6
# File 'lib/protobuf/descriptor/enum_descriptor.rb', line 4

def initialize(enum_class)
  @enum_class = enum_class
end

Instance Method Details

#build(proto, opt) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/protobuf/descriptor/enum_descriptor.rb', line 12

def build(proto, opt)
  mod = opt[:module]
  cls = mod.const_set(proto.name, Class.new(Protobuf::Enum))
  proto.value.each do |value_proto|
    cls.class_eval { define value_proto.name, value_proto.number }
  end
end

#proto_typeObject



8
9
10
# File 'lib/protobuf/descriptor/enum_descriptor.rb', line 8

def proto_type
  Google::Protobuf::EnumDescriptorProto
end

#unbuild(parent_proto) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/protobuf/descriptor/enum_descriptor.rb', line 20

def unbuild(parent_proto)
  enum_proto = Google::Protobuf::EnumDescriptorProto.new
  enum_proto.name = @enum_class.name.split('::').last
  @enum_class.values.each do |name, value|
    enum_value_proto = Google::Protobuf::EnumValueDescriptorProto.new
    enum_value_proto.name = name.to_s
    enum_value_proto.number = value.value
    enum_proto.value << enum_value_proto
  end
  parent_proto.enum_type << enum_proto
end