Module: Protobuf::Protoable

Included in:
Enum, Message
Defined in:
lib/protobuf/message/protoable.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) defined_filenames



3
4
5
# File 'lib/protobuf/message/protoable.rb', line 3

def defined_filenames
  @defined_filenames ||= []
end

- (Object) defined_in(filename)



7
8
9
10
# File 'lib/protobuf/message/protoable.rb', line 7

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

- (Object) proto_contents



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

- (Object) proto_filenames



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

- (Object) retrieve_header(contents)



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