Sha256: abca5b878ac99ed43a2e0c8f3c70373856311a71b746ad16fb571752e3afb8dc
Contents?: true
Size: 934 Bytes
Versions: 3
Compression:
Stored size: 934 Bytes
Contents
module Dry class Container module Stub # Overrides resolve to look into stubbed keys first # # @api public def resolve(key) _stubs.fetch(key) { super } end # Add a stub to the container def stub(key, value, &block) _stubs[key] = value if block yield unstub(key) end self end # Remove stubbed keys from the container def unstub(*keys) keys = _stubs.keys if keys.empty? keys.each { |key| _stubs.delete(key) } end # Stubs have already been enabled turning this into a noop def enable_stubs! end private # Stubs container def _stubs @_stubs ||= {} end end module Mixin # Enable stubbing functionality into the current container def enable_stubs! extend ::Dry::Container::Stub end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
dry-container-0.6.0 | lib/dry/container/stub.rb |
dry-container-0.5.0 | lib/dry/container/stub.rb |
dry-container-0.4.0 | lib/dry/container/stub.rb |