Class: Protod::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/protod/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



7
8
9
10
11
# File 'lib/protod/configuration.rb', line 7

def initialize
  @proto_root_dir = './proto'
  @pb_root_dir    = './lib'
  @builders       = {}
end

Instance Attribute Details

#pb_root_dirObject

Returns the value of attribute pb_root_dir.



5
6
7
# File 'lib/protod/configuration.rb', line 5

def pb_root_dir
  @pb_root_dir
end

#proto_root_dirObject

Returns the value of attribute proto_root_dir.



5
6
7
# File 'lib/protod/configuration.rb', line 5

def proto_root_dir
  @proto_root_dir
end

Instance Method Details

#buildersObject



62
63
64
# File 'lib/protod/configuration.rb', line 62

def builders
  @builders.values
end

#define_package(ident, for_ruby: nil, for_java: nil, &body) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/protod/configuration.rb', line 17

def define_package(ident, for_ruby: nil, for_java: nil, &body)
  bkup = @current_root_package

  raise NotImplementedError, "Unsupported nested package not yet!" if bkup

  @current_root_package = Protod.find_or_register_package(ident, for_ruby: for_ruby, for_java: for_java)

  body.call
ensure
  @current_root_package = bkup
end

#define_rpc(*names, singleton: false) ⇒ Object

Raises:

  • (NotImplementedError)


48
49
50
51
52
53
54
# File 'lib/protod/configuration.rb', line 48

def define_rpc(*names, singleton: false)
  raise NotImplementedError, "You need to call #define_package before" unless @current_root_package
  raise NotImplementedError, "You need to call #derive_from before" unless @current_const

  Protod::Rpc::Request.find_by(@current_const).push_procedure(*names, singleton: singleton)
  Protod::Rpc::Response.find_by(@current_const).push_procedure(*names, singleton: singleton)
end

#derive_from(const_name, abstruct: false, &body) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/protod/configuration.rb', line 29

def derive_from(const_name, abstruct: false, &body)
  raise NotImplementedError, "You need to call #define_package before" unless @current_root_package

  bkup = @current_const
  @current_const = bkup ? "#{bkup}::#{const_name.to_s.delete_prefix('::')}" : const_name.to_s.delete_prefix('::')

  Protod::Rpc::Request::Receiver.register_for(@current_const, force: false, ignore: true)
  Protod::Rpc::Response::Receiver.register_for(@current_const, force: false, ignore: true)

  unless abstruct
    builder = @builders[@current_root_package.full_ident] ||= Protod::Proto::Builder.new(@current_root_package)
    builder.push_receiver(@current_const)
  end

  body.call
ensure
  @current_const = bkup
end

#rbs_definition_builderObject



74
75
76
# File 'lib/protod/configuration.rb', line 74

def rbs_definition_builder
  @rbs_definition_builder ||= RBS::DefinitionBuilder.new(env: rbs_environment)
end

#rbs_environmentObject



66
67
68
69
70
71
72
# File 'lib/protod/configuration.rb', line 66

def rbs_environment
  @rbs_environment ||= RBS::EnvironmentLoader.new().tap do
    @setup_rbs_environment_loader&.call(_1)
  end.then do
    RBS::Environment.from_loader(_1).resolve_type_names
  end
end

#register_interpreter_for(*const_names, with: nil, force: true, &body) ⇒ Object

Raises:

  • (NotImplementedError)


56
57
58
59
60
# File 'lib/protod/configuration.rb', line 56

def register_interpreter_for(*const_names, with: nil, force: true, &body)
  raise NotImplementedError, "You need to call #define_package before" unless @current_root_package

  Protod::Interpreter.register_for(*const_names, with: with, force: force, &body)
end

#setup_rbs_environment_loader(&body) ⇒ Object



13
14
15
# File 'lib/protod/configuration.rb', line 13

def setup_rbs_environment_loader(&body)
  @setup_rbs_environment_loader = body
end