Module: Protobuf::Protoable
Instance Method Summary collapse
- #defined_filenames ⇒ Object
- #defined_in(filename) ⇒ Object
- #proto_contents ⇒ Object
- #proto_filenames ⇒ Object
- #retrieve_header(contents) ⇒ Object
Instance Method Details
#defined_filenames ⇒ Object
3 4 5 |
# File 'lib/protobuf/message/protoable.rb', line 3 def defined_filenames @defined_filenames ||= [] end |
#defined_in(filename) ⇒ Object
7 8 9 10 |
# File 'lib/protobuf/message/protoable.rb', line 7 def defined_in(filename) path = File.(filename) defined_filenames << path unless defined_filenames.include?(path) end |
#proto_contents ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/protobuf/message/protoable.rb', line 18 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 |
#proto_filenames ⇒ Object
12 13 14 15 16 |
# File 'lib/protobuf/message/protoable.rb', line 12 def proto_filenames defined_filenames.map do |filename| retrieve_header(File.read(filename)).first end end |
#retrieve_header(contents) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/protobuf/message/protoable.rb', line 28 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 |