Class: Dry::System::Provider
- Inherits:
-
Object
- Object
- Dry::System::Provider
- Defined in:
- lib/dry/system/provider.rb
Instance Attribute Summary collapse
-
#components ⇒ Object
readonly
Returns the value of attribute components.
-
#identifier ⇒ Object
readonly
Returns the value of attribute identifier.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #boot_file(name) ⇒ Object
- #boot_files ⇒ Object
- #boot_path ⇒ Object
- #component(name, options = {}) ⇒ Object
-
#initialize(identifier, options) ⇒ Provider
constructor
A new instance of Provider.
- #load_components ⇒ Object
- #register_component(name, fn) ⇒ Object
Constructor Details
#initialize(identifier, options) ⇒ Provider
Returns a new instance of Provider.
14 15 16 17 18 |
# File 'lib/dry/system/provider.rb', line 14 def initialize(identifier, ) @identifier = identifier @options = @components = Concurrent::Map.new end |
Instance Attribute Details
#components ⇒ Object (readonly)
Returns the value of attribute components.
12 13 14 |
# File 'lib/dry/system/provider.rb', line 12 def components @components end |
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
8 9 10 |
# File 'lib/dry/system/provider.rb', line 8 def identifier @identifier end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
10 11 12 |
# File 'lib/dry/system/provider.rb', line 10 def @options end |
Instance Method Details
#boot_file(name) ⇒ Object
32 33 34 |
# File 'lib/dry/system/provider.rb', line 32 def boot_file(name) boot_files.detect { |path| Pathname(path).basename(RB_EXT).to_s == name.to_s } end |
#boot_files ⇒ Object
24 25 26 |
# File 'lib/dry/system/provider.rb', line 24 def boot_files Dir[boot_path.join("**/#{RB_GLOB}")] end |
#boot_path ⇒ Object
20 21 22 |
# File 'lib/dry/system/provider.rb', line 20 def boot_path .fetch(:boot_path) end |
#component(name, options = {}) ⇒ Object
36 37 38 39 |
# File 'lib/dry/system/provider.rb', line 36 def component(name, = {}) identifier = [:key] || name components.fetch(identifier).new(name, ) end |
#load_components ⇒ Object
41 42 43 44 45 |
# File 'lib/dry/system/provider.rb', line 41 def load_components boot_files.each { |f| require f } freeze self end |
#register_component(name, fn) ⇒ Object
28 29 30 |
# File 'lib/dry/system/provider.rb', line 28 def register_component(name, fn) components[name] = Components::Bootable.new(name, &fn) end |