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 |
# File 'lib/protobuf/message/protoable.rb', line 7 def defined_in(filename) defined_filenames << File.(filename) end |
#proto_contents ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/protobuf/message/protoable.rb', line 17 def proto_contents #TODO: temporary implementation because the result includes not only this message but also all messages ret = {} defined_filenames.map do |filename| header = retrieve_header File.read(filename) ret[header.first] = header.last end ret end |
#proto_filenames ⇒ Object
11 12 13 14 15 |
# File 'lib/protobuf/message/protoable.rb', line 11 def proto_filenames defined_filenames.map do |filename| retrieve_header(File.read(filename)).first end end |
#retrieve_header(contents) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/protobuf/message/protoable.rb', line 27 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 |