Class: Protobuf::Descriptor::EnumDescriptor
- Inherits:
-
Object
- Object
- Protobuf::Descriptor::EnumDescriptor
- Defined in:
- lib/protobuf/descriptor/enum_descriptor.rb
Instance Method Summary collapse
- #build(proto, opt) ⇒ Object
-
#initialize(enum_class) ⇒ EnumDescriptor
constructor
A new instance of EnumDescriptor.
- #proto_type ⇒ Object
- #unbuild(parent_proto) ⇒ Object
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.const_set value_proto.name, value_proto.number end end |
#proto_type ⇒ Object
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.constants.each do |const| enum_value_proto = Google::Protobuf::EnumValueDescriptorProto.new enum_value_proto.name = const.to_s enum_value_proto.number = @enum_class.const_get const enum_proto.value << enum_value_proto end parent_proto.enum_type << enum_proto end |