Sha256: 1026977934f87576c749b96887c1bb5bc1aba7b460bf71204dbaf7b1ae9aa08a
Contents?: true
Size: 980 Bytes
Versions: 21
Compression:
Stored size: 980 Bytes
Contents
module Protobuf module Descriptor class EnumDescriptor def initialize(enum_class) @enum_class = enum_class end def proto_type Google::Protobuf::EnumDescriptorProto end 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 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 end end end
Version data entries
21 entries across 21 versions & 2 rubygems