Class: Dry::System::Booter Private
- Inherits:
-
Object
- Object
- Dry::System::Booter
- Defined in:
- lib/dry/system/booter.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.
Default booter implementation
This is currently configured by default for every System::Container. Booter objects are responsible for loading system/boot files and expose an API for calling lifecycle triggers.
Instance Attribute Summary collapse
- #booted ⇒ Object readonly private
- #finalizers ⇒ Object readonly private
- #path ⇒ Object readonly private
Instance Method Summary collapse
- #[]=(name, fn) ⇒ Object private
- #boot_dependency(component) ⇒ Object private
- #call(name) {|lifecycle| ... } ⇒ Object private
- #finalize! ⇒ Object private
- #init(name) ⇒ Object private
-
#initialize(path) ⇒ Booter
constructor
private
A new instance of Booter.
- #start(name) ⇒ Object private
Constructor Details
#initialize(path) ⇒ Booter
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 Booter.
21 22 23 24 25 |
# File 'lib/dry/system/booter.rb', line 21 def initialize(path) @path = path @booted = {} @finalizers = {} end |
Instance Attribute Details
#booted ⇒ 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.
18 19 20 |
# File 'lib/dry/system/booter.rb', line 18 def booted @booted end |
#finalizers ⇒ 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/booter.rb', line 16 def finalizers @finalizers end |
#path ⇒ 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.
14 15 16 |
# File 'lib/dry/system/booter.rb', line 14 def path @path end |
Instance Method Details
#[]=(name, fn) ⇒ 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.
28 29 30 31 |
# File 'lib/dry/system/booter.rb', line 28 def []=(name, fn) @finalizers[name] = fn self end |
#boot_dependency(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.
77 78 79 80 |
# File 'lib/dry/system/booter.rb', line 77 def boot_dependency(component) boot_file = component.boot_file(path) start(boot_file.basename('.*').to_s.to_sym) if boot_file.exist? end |
#call(name) {|lifecycle| ... } ⇒ 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.
66 67 68 69 70 71 72 73 74 |
# File 'lib/dry/system/booter.rb', line 66 def call(name) container, finalizer = finalizers[name] raise ComponentFileMismatchError.new(name, registered_booted_keys) unless finalizer lifecycle = Lifecycle.new(container, &finalizer) yield(lifecycle) if block_given? lifecycle end |
#finalize! ⇒ 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.
34 35 36 37 38 39 |
# File 'lib/dry/system/booter.rb', line 34 def finalize! Dir[boot_files].each do |path| start(File.basename(path, '.rb').to_sym) end freeze end |
#init(name) ⇒ 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.
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/dry/system/booter.rb', line 42 def init(name) Kernel.require(path.join(name.to_s)) call(name) do |lifecycle| lifecycle.(:init) yield(lifecycle) if block_given? end self end |
#start(name) ⇒ 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.
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/dry/system/booter.rb', line 54 def start(name) check_component_identifier(name) return self if booted.key?(name) init(name) { |lifecycle| lifecycle.(:start) } booted[name] = true self end |