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.5.0'

Class Method Summary collapse

Class Method Details

.[](*provider_keys) ⇒ 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
26
27
28
29
30
31
32
# File 'lib/providers.rb', line 20

def [](*provider_keys)
  provider_keys = [*provider_keys]

  raise(MissingProviderError, 'Pass one more provider keys') if provider_keys.empty?

  if provider_keys.count == 1
    result(provider_keys.first)
  else
    provider_keys.map do |provider_key|
      result(provider_key)
    end
  end
end

.allObject



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

def all
  providers
end

.clearObject



38
39
40
# File 'lib/providers.rb', line 38

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