Sha256: 43750f6ec64e6f9c48fd94dc4f7c88cac692a9ff57a4e96abf21d3bee561a749

Contents?: true

Size: 1.13 KB

Versions: 8

Compression:

Stored size: 1.13 KB

Contents

module Protobuf
  module Descriptor
    class FileDescriptor
      class <<self
        def proto_type
          'Google::Protobuf::FileDescriptorProto'
        end

        def build(proto, opt={})
          mod = Object
          if package = proto.package and not package.empty?
            module_names = package.split '::'
            module_names.each do |module_name|
              mod = mod.const_set module_name, Module.new
            end
          end
          proto.message_type.each do |message_proto|
            Protobuf::Message.descriptor.build message_proto, :module => mod
          end
          proto.enum_type.each do |enum_proto|
            Protobuf::Enum.descriptor.build enum_proto, :module => mod
          end
        end

        def unbuild(messages)
          messages = [messages] unless messages.is_a? Array
          proto = Google::Protobuf::FileDescriptorProto.new
          proto.package = messages.first.to_s.split('::')[0..-2].join('::') if messages.first.to_s =~ /::/
          messages.each do |message|
            message.descriptor.unbuild proto
          end
          proto
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
macks-ruby_protobuf-0.3.2.1 lib/protobuf/descriptor/file_descriptor.rb
macks-ruby_protobuf-0.3.2.2 lib/protobuf/descriptor/file_descriptor.rb
macks-ruby_protobuf-0.3.2.3 lib/protobuf/descriptor/file_descriptor.rb
macks-ruby_protobuf-0.3.3 lib/protobuf/descriptor/file_descriptor.rb
ruby_protobuf-0.3.3 lib/protobuf/descriptor/file_descriptor.rb
ruby_protobuf-0.3.2 lib/protobuf/descriptor/file_descriptor.rb
ruby_protobuf-0.3.0 lib/protobuf/descriptor/file_descriptor.rb
ruby_protobuf-0.2.0 lib/protobuf/descriptor/file_descriptor.rb