Class: Providers

Inherits:
Object
  • Object
show all
Defined in:
lib/providers.rb

Defined Under Namespace

Classes: MissingProviderError

Class Method Summary collapse

Class Method Details

.[](provider_key) ⇒ Object

Providers[] are hard to stub in tests and should only be used when dependency injection isn’t possible. TODO: Make Providers[] easy to stub in tests and look into feature where we get providers from another Ecosystem.



24
25
26
27
28
29
# File 'lib/providers.rb', line 24

def [](provider_key)
  provider = providers[provider_key]
  raise(MissingProviderError, "Provider #{provider_key.inspect} not found") if provider.nil?

  provider.result
end

.allObject



31
32
33
# File 'lib/providers.rb', line 31

def all
  providers
end

.clearObject



35
36
37
# File 'lib/providers.rb', line 35

def clear
  @providers = {}
end

.find(provider_key) ⇒ Object



18
19
20
# File 'lib/providers.rb', line 18

def find(provider_key)
  providers[provider_key]
end

.provide(key:, &block) ⇒ Object



9
10
11
# File 'lib/providers.rb', line 9

def provide(key:, &block)
  providers[key] = Provider.new(key:, &block)
end

.providersObject



13
14
15
16
# File 'lib/providers.rb', line 13

def providers
  @providers ||= {}
  @providers
end