Sha256: 4b7db5987cd2f9b60f3376590557790937905a96f3f36057c69a6b1b44389470

Contents?: true

Size: 1007 Bytes

Versions: 21

Compression:

Stored size: 1007 Bytes

Contents

module Protobuf
  module Protoable
    def defined_filenames
      @defined_filenames ||= []
    end

    def defined_in(filename)
      path = File.expand_path(filename)
      defined_filenames << path unless defined_filenames.include?(path)
    end

    def proto_filenames
      defined_filenames.map do |filename|
        retrieve_header(File.read(filename)).first
      end
    end

    def proto_contents
      #TODO: temporary implementation because the result includes not only this message but also all messages
      ret = {}
      defined_filenames.each do |filename|
        header = retrieve_header(File.read(filename))
        ret[header.first] = header.last
      end
      ret
    end

    def retrieve_header(contents)
      if contents =~ /### Generated by rprotoc\. DO NOT EDIT!\n### <proto file: (.*)>\n((# .*\n)+)/
        proto_filename = $1
        proto_contents = $2.gsub(/^# /, '')
        [proto_filename, proto_contents]
      else
        [nil, nil]
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 2 rubygems

Version Path
protobuf-1.4.2 lib/protobuf/message/protoable.rb
protobuf-1.4.1 lib/protobuf/message/protoable.rb
protobuf-1.4.0 lib/protobuf/message/protoable.rb
protobuf-1.3.0 lib/protobuf/message/protoable.rb
protobuf-1.1.3 lib/protobuf/message/protoable.rb
protobuf-1.1.2 lib/protobuf/message/protoable.rb
protobuf-1.1.1 lib/protobuf/message/protoable.rb
protobuf-1.1.0.beta2 lib/protobuf/message/protoable.rb
protobuf-1.1.0.beta1 lib/protobuf/message/protoable.rb
protobuf-1.1.0.beta0 lib/protobuf/message/protoable.rb
protobuf-1.0.1 lib/protobuf/message/protoable.rb
protobuf-1.0.0 lib/protobuf/message/protoable.rb
ruby_protobuf-0.4.11 lib/protobuf/message/protoable.rb
ruby_protobuf-0.4.10 lib/protobuf/message/protoable.rb
ruby_protobuf-0.4.9 lib/protobuf/message/protoable.rb
ruby_protobuf-0.4.8 lib/protobuf/message/protoable.rb
ruby_protobuf-0.4.7 lib/protobuf/message/protoable.rb
ruby_protobuf-0.4.6 lib/protobuf/message/protoable.rb
ruby_protobuf-0.4.5 lib/protobuf/message/protoable.rb
ruby_protobuf-0.4.4 lib/protobuf/message/protoable.rb