Class: Dry::System::Lifecycle Private
- Inherits:
- BasicObject
- Defined in:
- lib/dry/system/lifecycle.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Lifecycle booting DSL
Lifecycle objects are used in the boot files where you can register custom init/start/stop triggers
Instance Attribute Summary collapse
- #container ⇒ Object readonly private
- #init(&block) ⇒ Object readonly private
- #opts ⇒ Object readonly private
- #start(&block) ⇒ Object readonly private
- #statuses ⇒ Object readonly private
- #stop(&block) ⇒ Object readonly private
- #triggers ⇒ Object readonly private
Class Method Summary collapse
- .cache ⇒ Object private
- .new(container, opts = {}, &block) ⇒ Object private
Instance Method Summary collapse
- #call(*triggers) ⇒ Object private
- #component ⇒ Object private
- #config ⇒ Object private
- #configure(&block) ⇒ Object private
-
#initialize(container, opts, &block) ⇒ Lifecycle
constructor
private
A new instance of Lifecycle.
- #register(*args, &block) ⇒ Object private
- #settings(&block) ⇒ Object private
- #target ⇒ Object private
- #use(*names) ⇒ Object private
Constructor Details
#initialize(container, opts, &block) ⇒ Lifecycle
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Lifecycle.
43 44 45 46 47 48 49 50 |
# File 'lib/dry/system/lifecycle.rb', line 43 def initialize(container, opts, &block) @container = container @settings = nil @statuses = [] @triggers = {} @opts = opts instance_exec(target, &block) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/dry/system/lifecycle.rb', line 126 def method_missing(meth, *args, &block) if target.key?(meth) target[meth] elsif container.key?(meth) container[meth] elsif ::Kernel.respond_to?(meth) ::Kernel.public_send(meth, *args, &block) else super end end |
Instance Attribute Details
#container ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
16 17 18 |
# File 'lib/dry/system/lifecycle.rb', line 16 def container @container end |
#init(&block) ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
78 79 80 |
# File 'lib/dry/system/lifecycle.rb', line 78 def init @init end |
#opts ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
28 29 30 |
# File 'lib/dry/system/lifecycle.rb', line 28 def opts @opts end |
#start(&block) ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
83 84 85 |
# File 'lib/dry/system/lifecycle.rb', line 83 def start @start end |
#statuses ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
24 25 26 |
# File 'lib/dry/system/lifecycle.rb', line 24 def statuses @statuses end |
#stop(&block) ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
88 89 90 |
# File 'lib/dry/system/lifecycle.rb', line 88 def stop @stop end |
#triggers ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
26 27 28 |
# File 'lib/dry/system/lifecycle.rb', line 26 def triggers @triggers end |
Class Method Details
.cache ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
38 39 40 |
# File 'lib/dry/system/lifecycle.rb', line 38 def self.cache @cache ||= ::Concurrent::Map.new end |
.new(container, opts = {}, &block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
31 32 33 34 35 |
# File 'lib/dry/system/lifecycle.rb', line 31 def self.new(container, opts = {}, &block) cache.fetch_or_store([container, opts, block].hash) do super end end |
Instance Method Details
#call(*triggers) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
53 54 55 56 57 58 59 60 |
# File 'lib/dry/system/lifecycle.rb', line 53 def call(*triggers) triggers.each do |trigger| unless statuses.include?(trigger) __send__(trigger) statuses << trigger end end end |
#component ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
105 106 107 |
# File 'lib/dry/system/lifecycle.rb', line 105 def component opts[:component] end |
#config ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
73 74 75 |
# File 'lib/dry/system/lifecycle.rb', line 73 def config component.config end |
#configure(&block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
68 69 70 |
# File 'lib/dry/system/lifecycle.rb', line 68 def configure(&block) component.configure(&block) end |
#register(*args, &block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
100 101 102 |
# File 'lib/dry/system/lifecycle.rb', line 100 def register(*args, &block) container.register(*args, &block) end |
#settings(&block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
63 64 65 |
# File 'lib/dry/system/lifecycle.rb', line 63 def settings(&block) component.settings(&block) end |
#target ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
110 111 112 |
# File 'lib/dry/system/lifecycle.rb', line 110 def target component.container end |
#use(*names) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
93 94 95 96 97 |
# File 'lib/dry/system/lifecycle.rb', line 93 def use(*names) names.each do |name| target.start(name) end end |