canister 0.9.0 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +88 -9
- data/.travis.yml +6 -12
- data/README.md +18 -10
- data/canister.gemspec +4 -2
- data/lib/canister/version.rb +1 -1
- data/lib/canister.rb +29 -11
- metadata +39 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3d7d51a566030dbb120d909f6014bcea5248e0583ec03f9573a91282b43f8539
|
4
|
+
data.tar.gz: 06d8977666740bc732c54a658447f57929f130c59f9d6bda955211baa8bca8b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5d1623be13a5ba5d1116f6a343492795f49bbeffabf2a5b8230e102f149ddb32103f9dbe8849b5fe2a2a3e92ace5dd0ec69c62ba95e1a3d2c515bd9266bf240
|
7
|
+
data.tar.gz: ae25e1920021cdbf4a0741db85b31625227b2503f92d52d94d820c8a05c01dd59c2e7a89430e3944c1c1186a2e25fd953e7267cf2f8e34d1162842b8513fe4cb
|
data/.rubocop.yml
CHANGED
@@ -1,22 +1,37 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-performance
|
3
|
+
- rubocop-rspec
|
1
4
|
inherit_from: .rubocop_todo.yml
|
2
5
|
|
3
6
|
AllCops:
|
4
7
|
DisplayCopNames: true
|
5
8
|
TargetRubyVersion: 2.3
|
6
9
|
Exclude:
|
10
|
+
- '.bundle/**/*'
|
11
|
+
- 'vendor/bundle/**/*'
|
7
12
|
- '*.gemspec'
|
13
|
+
- 'spec/fixtures/**/*'
|
8
14
|
|
9
15
|
Naming/FileName:
|
10
16
|
ExpectMatchingDefinition: true
|
11
17
|
Exclude:
|
12
18
|
- 'bin/**/*'
|
19
|
+
- 'lib/core_extensions/**/*'
|
13
20
|
- 'spec/**/*'
|
14
21
|
- 'lib/*/version.rb'
|
15
22
|
|
23
|
+
RSpec/FilePath:
|
24
|
+
Exclude:
|
25
|
+
- 'spec/**/*.rb' # rubocop error
|
26
|
+
|
16
27
|
Style/Documentation:
|
17
28
|
Exclude:
|
18
29
|
- 'spec/**/*'
|
19
30
|
|
31
|
+
# Enabling this cop can break rescue statements in ruby <= 2.4
|
32
|
+
Style/RedundantBegin:
|
33
|
+
Enabled: false
|
34
|
+
|
20
35
|
# We disable this cop because we want to use Pathname#/
|
21
36
|
# and this cop is not configurable at all.
|
22
37
|
Layout/SpaceAroundOperators:
|
@@ -30,7 +45,7 @@ Style/Alias:
|
|
30
45
|
EnforcedStyle: prefer_alias_method
|
31
46
|
|
32
47
|
Metrics/LineLength:
|
33
|
-
Max:
|
48
|
+
Max: 90
|
34
49
|
AllowHeredoc: true
|
35
50
|
AllowURI: true
|
36
51
|
URISchemes:
|
@@ -39,15 +54,16 @@ Metrics/LineLength:
|
|
39
54
|
|
40
55
|
Metrics/BlockLength:
|
41
56
|
Exclude:
|
57
|
+
- 'spec/support/**/*.rb'
|
42
58
|
- 'spec/**/*_spec.rb'
|
43
59
|
|
44
60
|
Layout/ElseAlignment:
|
45
61
|
Enabled: false
|
46
62
|
|
47
|
-
Layout/
|
63
|
+
Layout/IndentFirstArgument:
|
48
64
|
EnforcedStyle: consistent
|
49
65
|
|
50
|
-
Layout/
|
66
|
+
Layout/AlignArguments:
|
51
67
|
EnforcedStyle: with_fixed_indentation
|
52
68
|
|
53
69
|
Layout/CaseIndentation:
|
@@ -59,6 +75,10 @@ Layout/ClosingParenthesisIndentation:
|
|
59
75
|
Style/ClassAndModuleChildren:
|
60
76
|
EnforcedStyle: nested
|
61
77
|
|
78
|
+
Metrics/ModuleLength:
|
79
|
+
Exclude:
|
80
|
+
- 'spec/**/*_spec.rb'
|
81
|
+
|
62
82
|
Style/CommentAnnotation:
|
63
83
|
Enabled: false
|
64
84
|
|
@@ -84,10 +104,10 @@ Style/GuardClause:
|
|
84
104
|
Style/IfUnlessModifier:
|
85
105
|
Enabled: false
|
86
106
|
|
87
|
-
Layout/
|
107
|
+
Layout/IndentFirstArrayElement:
|
88
108
|
EnforcedStyle: consistent
|
89
109
|
|
90
|
-
Layout/
|
110
|
+
Layout/IndentFirstHashElement:
|
91
111
|
EnforcedStyle: consistent
|
92
112
|
|
93
113
|
Layout/AlignHash:
|
@@ -126,14 +146,13 @@ Layout/SpaceInsideBlockBraces:
|
|
126
146
|
Style/SymbolArray:
|
127
147
|
EnforcedStyle: brackets
|
128
148
|
|
129
|
-
|
149
|
+
Layout/BlockAlignment:
|
130
150
|
EnforcedStyleAlignWith: start_of_block
|
131
|
-
#EnforcedStyleAlignWith: start_of_line
|
132
151
|
|
133
|
-
|
152
|
+
Layout/EndAlignment:
|
134
153
|
EnforcedStyleAlignWith: start_of_line
|
135
154
|
|
136
|
-
|
155
|
+
Layout/DefEndAlignment:
|
137
156
|
EnforcedStyleAlignWith: def
|
138
157
|
|
139
158
|
Performance/RedundantMerge:
|
@@ -142,3 +161,63 @@ Performance/RedundantMerge:
|
|
142
161
|
Style/WordArray:
|
143
162
|
EnforcedStyle: brackets
|
144
163
|
|
164
|
+
Style/RescueModifier:
|
165
|
+
Exclude:
|
166
|
+
- 'spec/**/*_spec.rb'
|
167
|
+
|
168
|
+
# This cop just adds extra work when you want to write an integration test,
|
169
|
+
# or test something like a jbuilder view.
|
170
|
+
RSpec/DescribeClass:
|
171
|
+
Enabled: false
|
172
|
+
|
173
|
+
# Using let! is fine, and can be easier to manage than a before block.
|
174
|
+
RSpec/LetSetup:
|
175
|
+
Enabled: false
|
176
|
+
|
177
|
+
RSpec/BeEql:
|
178
|
+
Enabled: false
|
179
|
+
|
180
|
+
RSpec/ExampleWithoutDescription:
|
181
|
+
EnforcedStyle: single_line_only
|
182
|
+
|
183
|
+
RSpec/HookArgument:
|
184
|
+
EnforcedStyle: each
|
185
|
+
|
186
|
+
RSpec/ImplicitSubject:
|
187
|
+
EnforcedStyle: disallow
|
188
|
+
|
189
|
+
RSpec/LeadingSubject:
|
190
|
+
Enabled: false
|
191
|
+
|
192
|
+
RSpec/MultipleExpectations:
|
193
|
+
Enabled: true
|
194
|
+
Max: 3
|
195
|
+
|
196
|
+
# Change this as needed.
|
197
|
+
RSpec/NestedGroups:
|
198
|
+
Max: 3
|
199
|
+
|
200
|
+
RSpec/VerifiedDoubles:
|
201
|
+
Enabled: false
|
202
|
+
|
203
|
+
RSpec/ExampleLength:
|
204
|
+
Max: 10
|
205
|
+
|
206
|
+
RSpec/MessageSpies:
|
207
|
+
EnforcedStyle: receive
|
208
|
+
|
209
|
+
RSpec/EmptyExampleGroup:
|
210
|
+
CustomIncludeMethods:
|
211
|
+
- it_allows
|
212
|
+
- it_disallows
|
213
|
+
|
214
|
+
RSpec/ContextWording:
|
215
|
+
Prefixes:
|
216
|
+
- as
|
217
|
+
- when
|
218
|
+
- with
|
219
|
+
- without
|
220
|
+
|
221
|
+
Lint/AmbiguousBlockAssociation:
|
222
|
+
Exclude:
|
223
|
+
- 'spec/**/*.rb'
|
data/.travis.yml
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
sudo: false
|
2
2
|
language: ruby
|
3
3
|
rvm:
|
4
|
+
- 2.6
|
5
|
+
- 2.5
|
4
6
|
- 2.4
|
5
7
|
- 2.3
|
6
8
|
|
@@ -9,20 +11,12 @@ branches:
|
|
9
11
|
- master
|
10
12
|
- develop
|
11
13
|
|
12
|
-
env:
|
13
|
-
global:
|
14
|
-
- CC_TEST_REPORTER_ID=a492448053c934b2a3cfa2f86f3357491d11beda5499db7884ae13859870fd29
|
15
|
-
|
16
14
|
before_install: gem install bundler
|
17
15
|
|
18
|
-
before_script:
|
19
|
-
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
20
|
-
- chmod +x ./cc-test-reporter
|
21
|
-
- ./cc-test-reporter before-build
|
22
|
-
|
23
16
|
script:
|
24
17
|
- bundle exec rspec --order=random
|
25
18
|
|
26
|
-
|
27
|
-
|
28
|
-
|
19
|
+
matrix:
|
20
|
+
include:
|
21
|
+
- rvm: ruby-head
|
22
|
+
script: bundle exec rubocop
|
data/README.md
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
# Canister
|
2
2
|
|
3
3
|
[![Build Status](https://travis-ci.org/mlibrary/canister.svg?branch=master)](https://travis-ci.org/mlibrary/canister)
|
4
|
-
[![
|
5
|
-
[![
|
6
|
-
|
4
|
+
[![Coverage Status](https://coveralls.io/repos/github/mlibrary/canister/badge.svg?branch=master)](https://coveralls.io/github/mlibrary/canister?branch=master)
|
5
|
+
[![API Docs](https://img.shields.io/badge/API_docs-rubydoc.info-blue.svg)](https://www.rubydoc.info/github/mlibrary/canister)
|
7
6
|
|
8
7
|
## Summary
|
9
8
|
|
@@ -20,19 +19,25 @@ It provides:
|
|
20
19
|
|
21
20
|
## Why do I need this? Especially in ruby?
|
22
21
|
|
23
|
-
Canister was created to make it easier to declare
|
22
|
+
Canister was created to make it easier to declare the setup for an application's
|
24
23
|
production and test environments in a single place, without needing to know
|
25
24
|
when exactly those objects were created.
|
26
25
|
|
27
26
|
*Canister is not a replacement for
|
28
27
|
dependency injection.* Rather, it is useful when you have designed your objects
|
29
|
-
to have their dependencies injected.
|
30
|
-
|
28
|
+
to have their dependencies injected.
|
29
|
+
|
30
|
+
The domain of your application is not concerned with the design
|
31
|
+
patterns you use to implement it; therefore, the domain entities within in it should
|
32
|
+
represent the domain, not the patterns.
|
33
|
+
For example, it would be a *mistake* to write all of your classes such that they
|
34
|
+
accept a single parameter called `container`. `Car.new(container)` is undesirable
|
35
|
+
when what your application really calls for is `Car.new(make, model, year)`.
|
31
36
|
|
32
37
|
For more information on dependency injection and inversion of control containers in
|
33
38
|
ruby, please see
|
34
39
|
[this excellent article](https://gist.github.com/malakai97/b1d3bdf6d80c6f99a875930981243f9d)
|
35
|
-
by [
|
40
|
+
by [Jim Weirich](https://en.wikipedia.org/wiki/Jim_Weirich) that both sums up the issue
|
36
41
|
and was the inspiration for this gem.
|
37
42
|
|
38
43
|
|
@@ -77,8 +82,11 @@ Standard rules apply.
|
|
77
82
|
|
78
83
|
## Compatibility
|
79
84
|
|
80
|
-
|
81
|
-
|
85
|
+
Canister has been tested on the following:
|
86
|
+
|
87
|
+
* ruby >= 2.3.x
|
88
|
+
* ruby >= 3.x
|
89
|
+
* jruby 9.4.2.0 (3.1.0)
|
82
90
|
|
83
91
|
As Canister does not rely on any specific runtime environment other than
|
84
92
|
the ruby core, it is compatible with every ruby library and framework.
|
@@ -88,7 +96,7 @@ the ruby core, it is compatible with every ruby library and framework.
|
|
88
96
|
* The author and maintainer is [Bryan Hockey](https://github.com/malakai97)
|
89
97
|
* This project was inspired by
|
90
98
|
[this excellent article](https://gist.github.com/malakai97/b1d3bdf6d80c6f99a875930981243f9d)
|
91
|
-
by [
|
99
|
+
by [Jim Weirich](https://en.wikipedia.org/wiki/Jim_Weirich). (We are not affiliated, so
|
92
100
|
don't blame him if this breaks.)
|
93
101
|
|
94
102
|
## License
|
data/canister.gemspec
CHANGED
@@ -25,9 +25,11 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
26
26
|
spec.require_paths = ["lib"]
|
27
27
|
|
28
|
-
spec.add_development_dependency "bundler"
|
28
|
+
spec.add_development_dependency "bundler"
|
29
|
+
spec.add_development_dependency "coveralls"
|
29
30
|
spec.add_development_dependency "rake", "~> 10.0"
|
30
31
|
spec.add_development_dependency "rspec", "~> 3.0"
|
31
32
|
spec.add_development_dependency "rubocop"
|
32
|
-
spec.add_development_dependency "
|
33
|
+
spec.add_development_dependency "rubocop-performance"
|
34
|
+
spec.add_development_dependency "rubocop-rspec"
|
33
35
|
end
|
data/lib/canister/version.rb
CHANGED
data/lib/canister.rb
CHANGED
@@ -15,6 +15,7 @@ class Canister
|
|
15
15
|
@dependents = Hash.new do |hash, key|
|
16
16
|
hash[key] = []
|
17
17
|
end
|
18
|
+
@mutex = Mutex.new
|
18
19
|
yield self if block_given?
|
19
20
|
end
|
20
21
|
|
@@ -34,6 +35,14 @@ class Canister
|
|
34
35
|
handles?(method) || super(method, include_all)
|
35
36
|
end
|
36
37
|
|
38
|
+
def synchronize(&block)
|
39
|
+
if @mutex.owned?
|
40
|
+
yield
|
41
|
+
else
|
42
|
+
@mutex.synchronize(&block)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
37
46
|
# Register a value to a key by passing a block. Note that
|
38
47
|
# the value will be that returned by the block. If the key
|
39
48
|
# has been registered before, the old registration is
|
@@ -43,8 +52,11 @@ class Canister
|
|
43
52
|
# @yield self [Container] Yields this container.
|
44
53
|
# @return the value defined in the block
|
45
54
|
def register(key, &block)
|
46
|
-
|
47
|
-
|
55
|
+
key = key.to_sym
|
56
|
+
synchronize do
|
57
|
+
invalidate(key) if registered?(key)
|
58
|
+
registry[key] = block
|
59
|
+
end
|
48
60
|
self
|
49
61
|
end
|
50
62
|
|
@@ -52,10 +64,14 @@ class Canister
|
|
52
64
|
# the key. This value is memoized.
|
53
65
|
# @param key [Symbol]
|
54
66
|
def resolve(key)
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
67
|
+
key = key.to_sym
|
68
|
+
value = nil
|
69
|
+
synchronize do
|
70
|
+
add_dependent(key)
|
71
|
+
stack << key
|
72
|
+
value = resolved[key] ||= registry[key].call(self)
|
73
|
+
stack.pop
|
74
|
+
end
|
59
75
|
value
|
60
76
|
end
|
61
77
|
alias_method :[], :resolve
|
@@ -74,23 +90,25 @@ class Canister
|
|
74
90
|
|
75
91
|
def add_dependent(key)
|
76
92
|
unless stack.empty?
|
77
|
-
dependents[key
|
93
|
+
dependents[key] << stack.last
|
78
94
|
end
|
79
95
|
end
|
80
96
|
|
81
97
|
def registered?(key)
|
82
|
-
registry.key?(key
|
98
|
+
registry.key?(key)
|
83
99
|
end
|
84
100
|
|
85
101
|
def unresolve(key)
|
86
|
-
resolved.delete(key
|
102
|
+
resolved.delete(key)
|
87
103
|
end
|
88
104
|
|
89
105
|
def invalidate(key, first = true)
|
90
106
|
unresolve(key)
|
91
|
-
dependents[key
|
107
|
+
dependents[key]
|
92
108
|
.each {|child| invalidate(child, false) }
|
93
|
-
|
109
|
+
if first
|
110
|
+
dependents.delete(key)
|
111
|
+
end
|
94
112
|
end
|
95
113
|
|
96
114
|
end
|
metadata
CHANGED
@@ -1,29 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: canister
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bryan Hockey
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-08-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: coveralls
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
25
39
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rake
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -67,7 +81,21 @@ dependencies:
|
|
67
81
|
- !ruby/object:Gem::Version
|
68
82
|
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
84
|
+
name: rubocop-performance
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop-rspec
|
71
99
|
requirement: !ruby/object:Gem::Requirement
|
72
100
|
requirements:
|
73
101
|
- - ">="
|
@@ -106,7 +134,7 @@ homepage: https://github.com/mlibrary/canister
|
|
106
134
|
licenses:
|
107
135
|
- Revised BSD
|
108
136
|
metadata: {}
|
109
|
-
post_install_message:
|
137
|
+
post_install_message:
|
110
138
|
rdoc_options: []
|
111
139
|
require_paths:
|
112
140
|
- lib
|
@@ -121,9 +149,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
121
149
|
- !ruby/object:Gem::Version
|
122
150
|
version: '0'
|
123
151
|
requirements: []
|
124
|
-
|
125
|
-
|
126
|
-
signing_key:
|
152
|
+
rubygems_version: 3.3.7
|
153
|
+
signing_key:
|
127
154
|
specification_version: 4
|
128
155
|
summary: A simple IoC container for ruby.
|
129
156
|
test_files: []
|