Sha256: ded4b750a4daed99f9fcc1005288b0aaed500de8d3886b6de8c7f77c44ae6b31

Contents?: true

Size: 981 Bytes

Versions: 5

Compression:

Stored size: 981 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.const_set 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.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
    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
macks-ruby_protobuf-0.3.2.1 lib/protobuf/descriptor/enum_descriptor.rb
macks-ruby_protobuf-0.3.2.2 lib/protobuf/descriptor/enum_descriptor.rb
macks-ruby_protobuf-0.3.2.3 lib/protobuf/descriptor/enum_descriptor.rb
macks-ruby_protobuf-0.3.3 lib/protobuf/descriptor/enum_descriptor.rb
ruby_protobuf-0.3.3 lib/protobuf/descriptor/enum_descriptor.rb