Class: Protobug::Compiler::Files

Inherits:
Object
  • Object
show all
Defined in:
lib/protobug/compiler.rb

Instance Method Summary collapse

Constructor Details

#initializeFiles

Returns a new instance of Files.



27
28
29
30
31
# File 'lib/protobug/compiler.rb', line 27

def initialize
  @descs_by_name = {}
  @files_by_path = {}
  @num_files = 0
end

Instance Method Details

#fetch(name) ⇒ Object



37
38
39
# File 'lib/protobug/compiler.rb', line 37

def fetch(name)
  @files_by_path.fetch(name)
end

#fetch_type(name) ⇒ Object



41
42
43
# File 'lib/protobug/compiler.rb', line 41

def fetch_type(name)
  @descs_by_name.fetch(name)
end

#register_decl(decl) ⇒ Object

Raises:

  • (ArgumentError)


45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/protobug/compiler.rb', line 45

def register_decl(decl)
  raise ArgumentError, "parent must be a Descriptor" if decl.parent && !decl.parent.is_a?(Descriptor)

  unless decl.is_a?(FileDescriptorProto)
    raise "already registered: #{decl.full_name}" if @descs_by_name[decl.full_name]

    @descs_by_name[decl.full_name] = decl
  end

  decl.each_declaration do |d|
    register_decl(d)
  end
  decl
end

#register_file(file) ⇒ Object



33
34
35
# File 'lib/protobug/compiler.rb', line 33

def register_file(file)
  @files_by_path[file.name] = register_decl(FileDescriptorProto.new(file, nil, path: []))
end