Class: Igniter::Embed::Contractable::SugarBuilder
- Inherits:
-
Object
- Object
- Igniter::Embed::Contractable::SugarBuilder
- Defined in:
- lib/igniter/embed/contractable/sugar_builder.rb
Instance Attribute Summary collapse
-
#configured ⇒ Object
readonly
Returns the value of attribute configured.
Instance Method Summary collapse
- #capture(**options) ⇒ Object
- #configured? ⇒ Boolean
- #discover(callable) ⇒ Object
-
#initialize(config:) ⇒ SugarBuilder
constructor
A new instance of SugarBuilder.
- #method_missing(name) ⇒ Object
- #migrate(from, to:) ⇒ Object
- #migration(from:, to:) ⇒ Object
- #observe(callable) ⇒ Object
- #on(event, callable = nil, &block) ⇒ Object
- #respond_to_missing?(name, include_private = false) ⇒ Boolean
- #shadow(async: nil, sample: nil) ⇒ Object
- #use(capability, adapter = nil, **options) ⇒ Object
Constructor Details
#initialize(config:) ⇒ SugarBuilder
Returns a new instance of SugarBuilder.
9 10 11 12 |
# File 'lib/igniter/embed/contractable/sugar_builder.rb', line 9 def initialize(config:) @config = config @configured = false end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name) ⇒ Object
96 97 98 99 100 101 102 103 |
# File 'lib/igniter/embed/contractable/sugar_builder.rb', line 96 def method_missing(name, ...) if config.respond_to?(name) mark_configured! return config.public_send(name, ...) end super end |
Instance Attribute Details
#configured ⇒ Object (readonly)
Returns the value of attribute configured.
7 8 9 |
# File 'lib/igniter/embed/contractable/sugar_builder.rb', line 7 def configured @configured end |
Instance Method Details
#capture(**options) ⇒ Object
50 51 52 53 |
# File 'lib/igniter/embed/contractable/sugar_builder.rb', line 50 def capture(**) mark_configured! config.(capture: ) end |
#configured? ⇒ Boolean
92 93 94 |
# File 'lib/igniter/embed/contractable/sugar_builder.rb', line 92 def configured? !!configured end |
#discover(callable) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/igniter/embed/contractable/sugar_builder.rb', line 35 def discover(callable) mark_configured! config.role :discovery_probe config.stage :profiled config.primary callable config end |
#migrate(from, to:) ⇒ Object
23 24 25 |
# File 'lib/igniter/embed/contractable/sugar_builder.rb', line 23 def migrate(from, to:) migration(from: from, to: to) end |
#migration(from:, to:) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/igniter/embed/contractable/sugar_builder.rb', line 14 def migration(from:, to:) mark_configured! config.role :migration_candidate config.stage :shadowed config.primary from config.candidate to config end |
#observe(callable) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/igniter/embed/contractable/sugar_builder.rb', line 27 def observe(callable) mark_configured! config.role :observed_service config.stage :captured config.primary callable config end |
#on(event, callable = nil, &block) ⇒ Object
87 88 89 90 |
# File 'lib/igniter/embed/contractable/sugar_builder.rb', line 87 def on(event, callable = nil, &block) mark_configured! config.on(event, callable, &block) end |
#respond_to_missing?(name, include_private = false) ⇒ Boolean
105 106 107 |
# File 'lib/igniter/embed/contractable/sugar_builder.rb', line 105 def respond_to_missing?(name, include_private = false) config.respond_to?(name, include_private) || super end |
#shadow(async: nil, sample: nil) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/igniter/embed/contractable/sugar_builder.rb', line 43 def shadow(async: nil, sample: nil) mark_configured! config.async(async) unless async.nil? config.sample(sample) unless sample.nil? config end |
#use(capability, adapter = nil, **options) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/igniter/embed/contractable/sugar_builder.rb', line 55 def use(capability, adapter = nil, **) mark_configured! case capability.to_sym when :normalizer require_adapter!(capability, adapter) config.normalize_primary adapter config.normalize_candidate adapter when :redaction config.redact_inputs adapter || redaction_adapter(**) config.redaction_input_policy = if adapter :custom elsif [:only] :only else :except end when :acceptance raise SugarError, "use :acceptance requires policy:" unless .key?(:policy) policy = .fetch(:policy) config.accept policy, **.reject { |key, _value| key == :policy } when :store require_adapter!(capability, adapter) config.store adapter when :logging, :reporting, :metrics, :validation config.capability capability, explicit_capability_target(capability, adapter, **) else raise SugarError, "use :#{capability} is not supported in this implementation slice" end config end |