module Dry::Container::Stub
Public Instance Methods
enable_stubs!()
click to toggle source
Stubs have already been enabled turning this into a noop
# File lib/dry/container/stub.rb, line 34 def enable_stubs! # DO NOTHING end
resolve(key)
click to toggle source
Overrides resolve to look into stubbed keys first
@api public
Calls superclass method
# File lib/dry/container/stub.rb, line 7 def resolve(key) _stubs.fetch(key.to_s) { super } end
stub(key, value) { || ... }
click to toggle source
Add a stub to the container
# File lib/dry/container/stub.rb, line 12 def stub(key, value, &block) unless key?(key) raise ArgumentError, "cannot stub #{ key.to_s.inspect } - no such key in container" end _stubs[key.to_s] = value if block yield unstub(key) end self end
unstub(*keys)
click to toggle source
Remove stubbed keys from the container
# File lib/dry/container/stub.rb, line 28 def unstub(*keys) keys = _stubs.keys if keys.empty? keys.each { |key| _stubs.delete(key.to_s) } end
Private Instance Methods
_stubs()
click to toggle source
Stubs container
# File lib/dry/container/stub.rb, line 41 def _stubs @_stubs ||= {} end