Class: Protod::Configuration
- Inherits:
-
Object
- Object
- Protod::Configuration
- Defined in:
- lib/protod/configuration.rb
Instance Attribute Summary collapse
-
#pb_root_dir ⇒ Object
Returns the value of attribute pb_root_dir.
-
#proto_root_dir ⇒ Object
Returns the value of attribute proto_root_dir.
Instance Method Summary collapse
- #builders ⇒ Object
- #define_package(ident, for_ruby: nil, for_java: nil, &body) ⇒ Object
- #define_rpc(*names, singleton: false) ⇒ Object
- #derive_from(const_name, abstruct: false, &body) ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #rbs_definition_builder ⇒ Object
- #rbs_environment ⇒ Object
- #register_interpreter_for(*const_names, with: nil, force: true, &body) ⇒ Object
- #setup_rbs_environment_loader(&body) ⇒ Object
Constructor Details
#initialize ⇒ Configuration
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_dir ⇒ Object
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_dir ⇒ Object
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
#builders ⇒ Object
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
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_builder ⇒ Object
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_environment ⇒ Object
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
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 |