Class: Dry::System::Provider

Inherits:
Object
  • Object
show all
Defined in:
lib/dry/system/provider.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options)
  @identifier = identifier
  @options = options
  @components = Concurrent::Map.new
end

Instance Attribute Details

#componentsObject (readonly)

Returns the value of attribute components.


12
13
14
# File 'lib/dry/system/provider.rb', line 12

def components
  @components
end

#identifierObject (readonly)

Returns the value of attribute identifier.


8
9
10
# File 'lib/dry/system/provider.rb', line 8

def identifier
  @identifier
end

#optionsObject (readonly)

Returns the value of attribute options.


10
11
12
# File 'lib/dry/system/provider.rb', line 10

def options
  @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_filesObject


24
25
26
# File 'lib/dry/system/provider.rb', line 24

def boot_files
  Dir[boot_path.join("**/#{RB_GLOB}")]
end

#boot_pathObject


20
21
22
# File 'lib/dry/system/provider.rb', line 20

def boot_path
  options.fetch(:boot_path)
end

#component(name, options = {}) ⇒ Object


36
37
38
39
# File 'lib/dry/system/provider.rb', line 36

def component(name, options = {})
  identifier = options[:key] || name
  components.fetch(identifier).new(name, options)
end

#load_componentsObject


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