dry-container 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +76 -27
- data/LICENSE +1 -1
- data/README.md +20 -14
- data/dry-container.gemspec +35 -22
- data/lib/dry/container/error.rb +2 -0
- data/lib/dry/container/item/callable.rb +3 -8
- data/lib/dry/container/item/factory.rb +4 -2
- data/lib/dry/container/item/memoizable.rb +5 -5
- data/lib/dry/container/item.rb +23 -0
- data/lib/dry/container/mixin.rb +44 -17
- data/lib/dry/container/namespace.rb +2 -0
- data/lib/dry/container/namespace_dsl.rb +3 -1
- data/lib/dry/container/registry.rb +3 -1
- data/lib/dry/container/resolver.rb +13 -3
- data/lib/dry/container/stub.rb +3 -1
- data/lib/dry/container/version.rb +3 -1
- data/lib/dry/container.rb +10 -8
- data/lib/dry-container.rb +3 -1
- metadata +30 -45
- data/.codeclimate.yml +0 -32
- data/.gitignore +0 -9
- data/.rspec +0 -2
- data/.rubocop.yml +0 -24
- data/.rubocop_todo.yml +0 -6
- data/.travis.yml +0 -27
- data/CONTRIBUTING.md +0 -29
- data/Gemfile +0 -19
- data/Rakefile +0 -12
- data/rakelib/rubocop.rake +0 -18
- data/spec/integration/container_spec.rb +0 -18
- data/spec/integration/mixin_spec.rb +0 -32
- data/spec/spec_helper.rb +0 -102
- data/spec/support/shared_examples/container.rb +0 -577
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Dry
|
2
4
|
class Container
|
3
5
|
# Default resolver for resolving items from container
|
@@ -10,16 +12,24 @@ module Dry
|
|
10
12
|
# The container
|
11
13
|
# @param [Mixed] key
|
12
14
|
# The key for the item you wish to resolve
|
15
|
+
# @yield
|
16
|
+
# Fallback block to call when a key is missing. Its result will be returned
|
17
|
+
# @yieldparam [Mixed] key Missing key
|
18
|
+
#
|
19
|
+
# @raise [Dry::Container::Error]
|
20
|
+
# If the given key is not registered with the container (and no block provided)
|
13
21
|
#
|
14
|
-
# @raise [Dry::Conainer::Error]
|
15
|
-
# If the given key is not registered with the container
|
16
22
|
#
|
17
23
|
# @return [Mixed]
|
18
24
|
#
|
19
25
|
# @api public
|
20
26
|
def call(container, key)
|
21
27
|
item = container.fetch(key.to_s) do
|
22
|
-
|
28
|
+
if block_given?
|
29
|
+
return yield(key)
|
30
|
+
else
|
31
|
+
raise Error, "Nothing registered with the key #{key.inspect}"
|
32
|
+
end
|
23
33
|
end
|
24
34
|
|
25
35
|
item.call
|
data/lib/dry/container/stub.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Dry
|
2
4
|
class Container
|
3
5
|
module Stub
|
@@ -11,7 +13,7 @@ module Dry
|
|
11
13
|
# Add a stub to the container
|
12
14
|
def stub(key, value, &block)
|
13
15
|
unless key?(key)
|
14
|
-
raise ArgumentError, "cannot stub #{
|
16
|
+
raise ArgumentError, "cannot stub #{key.to_s.inspect} - no such key in container"
|
15
17
|
end
|
16
18
|
|
17
19
|
_stubs[key.to_s] = value
|
data/lib/dry/container.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "dry-configurable"
|
4
|
+
require "dry/container/error"
|
5
|
+
require "dry/container/namespace"
|
6
|
+
require "dry/container/registry"
|
7
|
+
require "dry/container/resolver"
|
8
|
+
require "dry/container/namespace_dsl"
|
9
|
+
require "dry/container/mixin"
|
10
|
+
require "dry/container/version"
|
9
11
|
|
10
12
|
# A collection of micro-libraries, each intended to encapsulate
|
11
13
|
# a common task in Ruby
|
data/lib/dry-container.rb
CHANGED
metadata
CHANGED
@@ -1,110 +1,101 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dry-container
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Holland
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-09-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
+
name: concurrent-ruby
|
14
15
|
requirement: !ruby/object:Gem::Requirement
|
15
16
|
requirements:
|
16
17
|
- - "~>"
|
17
18
|
- !ruby/object:Gem::Version
|
18
19
|
version: '1.0'
|
19
|
-
name: concurrent-ruby
|
20
|
-
prerelease: false
|
21
20
|
type: :runtime
|
21
|
+
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
+
name: dry-configurable
|
28
29
|
requirement: !ruby/object:Gem::Requirement
|
29
30
|
requirements:
|
30
31
|
- - "~>"
|
31
32
|
- !ruby/object:Gem::Version
|
32
|
-
version: '0.
|
33
|
+
version: '0.13'
|
33
34
|
- - ">="
|
34
35
|
- !ruby/object:Gem::Version
|
35
|
-
version: 0.
|
36
|
-
name: dry-configurable
|
37
|
-
prerelease: false
|
36
|
+
version: 0.13.0
|
38
37
|
type: :runtime
|
38
|
+
prerelease: false
|
39
39
|
version_requirements: !ruby/object:Gem::Requirement
|
40
40
|
requirements:
|
41
41
|
- - "~>"
|
42
42
|
- !ruby/object:Gem::Version
|
43
|
-
version: '0.
|
43
|
+
version: '0.13'
|
44
44
|
- - ">="
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version: 0.
|
46
|
+
version: 0.13.0
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
|
+
name: bundler
|
48
49
|
requirement: !ruby/object:Gem::Requirement
|
49
50
|
requirements:
|
50
51
|
- - ">="
|
51
52
|
- !ruby/object:Gem::Version
|
52
53
|
version: '0'
|
53
|
-
name: bundler
|
54
|
-
prerelease: false
|
55
54
|
type: :development
|
55
|
+
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|
58
58
|
- - ">="
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: '0'
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
|
+
name: rake
|
62
63
|
requirement: !ruby/object:Gem::Requirement
|
63
64
|
requirements:
|
64
65
|
- - ">="
|
65
66
|
- !ruby/object:Gem::Version
|
66
67
|
version: '0'
|
67
|
-
name: rake
|
68
|
-
prerelease: false
|
69
68
|
type: :development
|
69
|
+
prerelease: false
|
70
70
|
version_requirements: !ruby/object:Gem::Requirement
|
71
71
|
requirements:
|
72
72
|
- - ">="
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: '0'
|
75
75
|
- !ruby/object:Gem::Dependency
|
76
|
+
name: rspec
|
76
77
|
requirement: !ruby/object:Gem::Requirement
|
77
78
|
requirements:
|
78
79
|
- - ">="
|
79
80
|
- !ruby/object:Gem::Version
|
80
81
|
version: '0'
|
81
|
-
name: rspec
|
82
|
-
prerelease: false
|
83
82
|
type: :development
|
83
|
+
prerelease: false
|
84
84
|
version_requirements: !ruby/object:Gem::Requirement
|
85
85
|
requirements:
|
86
86
|
- - ">="
|
87
87
|
- !ruby/object:Gem::Version
|
88
88
|
version: '0'
|
89
|
-
description:
|
89
|
+
description: A simple, configurable object container implemented in Ruby
|
90
90
|
email:
|
91
91
|
- andyholland1991@aol.com
|
92
92
|
executables: []
|
93
93
|
extensions: []
|
94
94
|
extra_rdoc_files: []
|
95
95
|
files:
|
96
|
-
- ".codeclimate.yml"
|
97
|
-
- ".gitignore"
|
98
|
-
- ".rspec"
|
99
|
-
- ".rubocop.yml"
|
100
|
-
- ".rubocop_todo.yml"
|
101
|
-
- ".travis.yml"
|
102
96
|
- CHANGELOG.md
|
103
|
-
- CONTRIBUTING.md
|
104
|
-
- Gemfile
|
105
97
|
- LICENSE
|
106
98
|
- README.md
|
107
|
-
- Rakefile
|
108
99
|
- dry-container.gemspec
|
109
100
|
- lib/dry-container.rb
|
110
101
|
- lib/dry/container.rb
|
@@ -120,16 +111,15 @@ files:
|
|
120
111
|
- lib/dry/container/resolver.rb
|
121
112
|
- lib/dry/container/stub.rb
|
122
113
|
- lib/dry/container/version.rb
|
123
|
-
-
|
124
|
-
- spec/integration/container_spec.rb
|
125
|
-
- spec/integration/mixin_spec.rb
|
126
|
-
- spec/spec_helper.rb
|
127
|
-
- spec/support/shared_examples/container.rb
|
128
|
-
homepage: https://github.com/dry-rb/dry-container
|
114
|
+
homepage: https://dry-rb.org/gems/dry-container
|
129
115
|
licenses:
|
130
116
|
- MIT
|
131
|
-
metadata:
|
132
|
-
|
117
|
+
metadata:
|
118
|
+
allowed_push_host: https://rubygems.org
|
119
|
+
changelog_uri: https://github.com/dry-rb/dry-container/blob/master/CHANGELOG.md
|
120
|
+
source_code_uri: https://github.com/dry-rb/dry-container
|
121
|
+
bug_tracker_uri: https://github.com/dry-rb/dry-container/issues
|
122
|
+
post_install_message:
|
133
123
|
rdoc_options: []
|
134
124
|
require_paths:
|
135
125
|
- lib
|
@@ -137,20 +127,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
137
127
|
requirements:
|
138
128
|
- - ">="
|
139
129
|
- !ruby/object:Gem::Version
|
140
|
-
version: 2.
|
130
|
+
version: 2.6.0
|
141
131
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
142
132
|
requirements:
|
143
133
|
- - ">="
|
144
134
|
- !ruby/object:Gem::Version
|
145
135
|
version: '0'
|
146
136
|
requirements: []
|
147
|
-
|
148
|
-
|
149
|
-
signing_key:
|
137
|
+
rubygems_version: 3.1.6
|
138
|
+
signing_key:
|
150
139
|
specification_version: 4
|
151
|
-
summary: A simple
|
152
|
-
test_files:
|
153
|
-
- spec/integration/container_spec.rb
|
154
|
-
- spec/integration/mixin_spec.rb
|
155
|
-
- spec/spec_helper.rb
|
156
|
-
- spec/support/shared_examples/container.rb
|
140
|
+
summary: A simple, configurable object container implemented in Ruby
|
141
|
+
test_files: []
|
data/.codeclimate.yml
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
engines:
|
2
|
-
rubocop:
|
3
|
-
enabled: true
|
4
|
-
checks:
|
5
|
-
Rubocop/Metrics/LineLength:
|
6
|
-
enabled: true
|
7
|
-
max: 120
|
8
|
-
Rubocop/Style/Documentation:
|
9
|
-
enabled: false
|
10
|
-
Rubocop/Lint/HandleExceptions:
|
11
|
-
enabled: true
|
12
|
-
exclude:
|
13
|
-
- rakelib/*.rake
|
14
|
-
Rubocop/Lint/NestedMethodDefinition:
|
15
|
-
enabled: true
|
16
|
-
exclude:
|
17
|
-
- lib/dry/container/mixin.rb
|
18
|
-
Rubocop/Metrics/MethodLength:
|
19
|
-
enabled: true
|
20
|
-
exclude:
|
21
|
-
- lib/dry/container/mixin.rb
|
22
|
-
Rubocop/Style/FileName:
|
23
|
-
enabled: true
|
24
|
-
exclude:
|
25
|
-
- lib/dry-container.rb
|
26
|
-
|
27
|
-
ratings:
|
28
|
-
paths:
|
29
|
-
- lib/**/*.rb
|
30
|
-
exclude_paths:
|
31
|
-
- spec/**/*
|
32
|
-
- examples/**/*
|
data/.gitignore
DELETED
data/.rspec
DELETED
data/.rubocop.yml
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
# Generated by `rubocop --auto-gen-config`
|
2
|
-
inherit_from: .rubocop_todo.yml
|
3
|
-
|
4
|
-
Metrics/LineLength:
|
5
|
-
Max: 120
|
6
|
-
|
7
|
-
Style/Documentation:
|
8
|
-
Enabled: false
|
9
|
-
|
10
|
-
Lint/HandleExceptions:
|
11
|
-
Exclude:
|
12
|
-
- rakelib/*.rake
|
13
|
-
|
14
|
-
Lint/NestedMethodDefinition:
|
15
|
-
Exclude:
|
16
|
-
- lib/dry/container/mixin.rb
|
17
|
-
|
18
|
-
Metrics/MethodLength:
|
19
|
-
Exclude:
|
20
|
-
- lib/dry/container/mixin.rb
|
21
|
-
|
22
|
-
Style/FileName:
|
23
|
-
Exclude:
|
24
|
-
- lib/dry-container.rb
|
data/.rubocop_todo.yml
DELETED
@@ -1,6 +0,0 @@
|
|
1
|
-
# This configuration was generated by `rubocop --auto-gen-config`
|
2
|
-
# on 2015-06-16 19:51:19 +0100 using RuboCop version 0.32.0.
|
3
|
-
# The point is for the user to remove these configuration records
|
4
|
-
# one by one as the offenses are removed from the code base.
|
5
|
-
# Note that changes in the inspected code, or installation of new
|
6
|
-
# versions of RuboCop, may require this file to be generated again.
|
data/.travis.yml
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
dist: trusty
|
3
|
-
sudo: required
|
4
|
-
cache: bundler
|
5
|
-
bundler_args: --without console
|
6
|
-
script:
|
7
|
-
- bundle exec rake spec
|
8
|
-
after_success:
|
9
|
-
- '[ -d coverage ] && bundle exec codeclimate-test-reporter'
|
10
|
-
rvm:
|
11
|
-
- 2.3.8
|
12
|
-
- 2.4.5
|
13
|
-
- 2.5.3
|
14
|
-
- 2.6.1
|
15
|
-
- jruby-9.2.5.0
|
16
|
-
env:
|
17
|
-
global:
|
18
|
-
- JRUBY_OPTS='--dev -J-Xmx1024M'
|
19
|
-
- COVERAGE='true'
|
20
|
-
notifications:
|
21
|
-
email: false
|
22
|
-
webhooks:
|
23
|
-
urls:
|
24
|
-
- https://webhooks.gitter.im/e/19098b4253a72c9796db
|
25
|
-
on_success: change # options: [always|never|change] default: always
|
26
|
-
on_failure: always # options: [always|never|change] default: always
|
27
|
-
on_start: false # default: false
|
data/CONTRIBUTING.md
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
# Issue Guidelines
|
2
|
-
|
3
|
-
## Reporting bugs
|
4
|
-
|
5
|
-
If you found a bug, report an issue and describe what's the expected behavior versus what actually happens. If the bug causes a crash, attach a full backtrace. If possible, a reproduction script showing the problem is highly appreciated.
|
6
|
-
|
7
|
-
## Reporting feature requests
|
8
|
-
|
9
|
-
Report a feature request **only after discussing it first on [discourse.dry-rb.org](http://discourse.dry-rb.org)** where it was accepted. Please provide a concise description of the feature, don't link to a discussion thread, and instead summarize what was discussed.
|
10
|
-
|
11
|
-
## Reporting questions, support requests, ideas, concerns etc.
|
12
|
-
|
13
|
-
**PLEASE DON'T** - use [discourse.dry-rb.org](http://discourse.dry-rb.org) instead.
|
14
|
-
|
15
|
-
# Pull Request Guidelines
|
16
|
-
|
17
|
-
A Pull Request will only be accepted if it addresses a specific issue that was reported previously, or fixes typos, mistakes in documentation etc.
|
18
|
-
|
19
|
-
Other requirements:
|
20
|
-
|
21
|
-
1) Do not open a pull request if you can't provide tests along with it. If you have problems writing tests, ask for help in the related issue.
|
22
|
-
2) Follow the style conventions of the surrounding code. In most cases, this is standard ruby style.
|
23
|
-
3) Add API documentation if it's a new feature
|
24
|
-
4) Update API documentation if it changes an existing feature
|
25
|
-
5) Bonus points for sending a PR to [github.com/dry-rb/dry-rb.org](github.com/dry-rb/dry-rb.org) which updates user documentation and guides
|
26
|
-
|
27
|
-
# Asking for help
|
28
|
-
|
29
|
-
If these guidelines aren't helpful, and you're stuck, please post a message on [[discourse.dry-rb.org](http://discourse.dry-rb.org).
|
data/Gemfile
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
|
3
|
-
gemspec
|
4
|
-
|
5
|
-
group :test do
|
6
|
-
platforms :mri do
|
7
|
-
gem 'codeclimate-test-reporter', require: false
|
8
|
-
gem 'simplecov', require: false
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
group :tools do
|
13
|
-
gem 'rubocop'
|
14
|
-
gem 'guard'
|
15
|
-
gem 'guard-rspec'
|
16
|
-
gem 'guard-rubocop'
|
17
|
-
gem 'listen', '3.0.6'
|
18
|
-
gem 'pry-byebug', platform: :mri
|
19
|
-
end
|