Module: Providers

Defined in:
lib/version.rb,
lib/providers.rb,
lib/providers/provider.rb

Defined Under Namespace

Classes: MissingProviderError, Provider

Constant Summary collapse

VERSION =
'0.4.0'

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.



20
21
22
23
24
25
# File 'lib/providers.rb', line 20

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

  provider.result
end

.allObject



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

def all
  providers
end

.clearObject



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

def clear
  @providers = {}
end

.define(key, &block) ⇒ Object



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

def define(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