Class: Igniter::Embed::Container
- Inherits:
-
Object
- Object
- Igniter::Embed::Container
- Defined in:
- lib/igniter/embed/container.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#registry ⇒ Object
readonly
Returns the value of attribute registry.
Instance Method Summary collapse
- #call(name, inputs = {}, **keyword_inputs) ⇒ Object
- #clear_cache ⇒ Object
- #compile(name = nil, &block) ⇒ Object
- #contractable(name) ⇒ Object (also: #fetch_contractable)
- #contractable_names ⇒ Object
- #fetch(name) ⇒ Object
-
#initialize(config:) ⇒ Container
constructor
A new instance of Container.
- #profile ⇒ Object
- #register(name_or_definition, definition = nil, as: nil, &block) ⇒ Object
- #reload! ⇒ Object
- #sugar_expansion ⇒ Object
Constructor Details
#initialize(config:) ⇒ Container
Returns a new instance of Container.
8 9 10 11 12 13 14 15 |
# File 'lib/igniter/embed/container.rb', line 8 def initialize(config:) @config = config @registry = Registry.new @compiled_contracts = {} @contractable_runners = {} register_configured_contracts discover_configured_contracts end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
6 7 8 |
# File 'lib/igniter/embed/container.rb', line 6 def config @config end |
#registry ⇒ Object (readonly)
Returns the value of attribute registry.
6 7 8 |
# File 'lib/igniter/embed/container.rb', line 6 def registry @registry end |
Instance Method Details
#call(name, inputs = {}, **keyword_inputs) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/igniter/embed/container.rb', line 41 def call(name, inputs = {}, **keyword_inputs) normalized_inputs = inputs.merge(keyword_inputs) compiled_graph = compile_registered(name) result = Igniter::Contracts.execute_with( config.executor_name, compiled_graph, inputs: normalized_inputs, profile: profile ) ExecutionEnvelope.new(name: name, inputs: normalized_inputs, result: result) rescue StandardError => e raise unless config.capture_exceptions? ExecutionEnvelope.new( name: name, inputs: normalized_inputs || {}, errors: [e], metadata: { captured_exception: true } ) end |
#clear_cache ⇒ Object
77 78 79 80 81 82 |
# File 'lib/igniter/embed/container.rb', line 77 def clear_cache compiled_contracts.clear contractable_runners.clear @profile = nil self end |
#compile(name = nil, &block) ⇒ Object
35 36 37 38 39 |
# File 'lib/igniter/embed/container.rb', line 35 def compile(name = nil, &block) return compile_block(&block) if block compile_registered(name) end |
#contractable(name) ⇒ Object Also known as: fetch_contractable
62 63 64 65 66 67 68 69 70 |
# File 'lib/igniter/embed/container.rb', line 62 def contractable(name) key = name.to_sym return contractable_runners.fetch(key) if contractable_runners.key?(key) contractable_config = config.contractable_config(key) raise UnknownContractableError, "unknown contractable #{key}" unless contractable_config contractable_runners[key] = Contractable::Runner.new(config: contractable_config) end |
#contractable_names ⇒ Object
73 74 75 |
# File 'lib/igniter/embed/container.rb', line 73 def contractable_names config.contractable_configs.map(&:name) end |
#fetch(name) ⇒ Object
30 31 32 33 |
# File 'lib/igniter/embed/container.rb', line 30 def fetch(name) registry.fetch(name) ContractHandle.new(name: name, container: self) end |
#profile ⇒ Object
17 18 19 |
# File 'lib/igniter/embed/container.rb', line 17 def profile @profile ||= Igniter::Contracts.build_profile(config.packs) end |
#register(name_or_definition, definition = nil, as: nil, &block) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/igniter/embed/container.rb', line 21 def register(name_or_definition, definition = nil, as: nil, &block) name, contract_definition = normalize_registration(name_or_definition, definition, as: as, block: block) raise ArgumentError, "contract definition is required" unless contract_definition registry.register(name, contract_definition) compiled_contracts.delete(name) ContractHandle.new(name: name, container: self) end |
#reload! ⇒ Object
84 85 86 |
# File 'lib/igniter/embed/container.rb', line 84 def reload! clear_cache end |
#sugar_expansion ⇒ Object
88 89 90 |
# File 'lib/igniter/embed/container.rb', line 88 def sugar_expansion config.sugar_expansion end |