canister 0.9.1 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5d114b43d3e9ee866a97c45b52153345d9ce2008360f4510ff6852276a74ed8a
4
- data.tar.gz: 66fffaf9a4c45c7980c038e8142365eac794ea93d8e7b1627749e3a9e4c77f00
3
+ metadata.gz: 3d7d51a566030dbb120d909f6014bcea5248e0583ec03f9573a91282b43f8539
4
+ data.tar.gz: 06d8977666740bc732c54a658447f57929f130c59f9d6bda955211baa8bca8b7
5
5
  SHA512:
6
- metadata.gz: 2a5908fdc9d394850275fcdb1f30f24e6d6dbb5e088cddf74965bacc562191d15c0eec3367b98218b6daa911d564d2f74ce019f29639223ab0e572e3903ffd25
7
- data.tar.gz: 580c0a3e95ada241f4f8d4d56f14eb5557ee29073810c33b0e7ed42d695ee1ef9aad85e51fde8c5f577ba3f8efde7ba62766104409539e16a8f2bb2503552971
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: 100
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/FirstParameterIndentation:
63
+ Layout/IndentFirstArgument:
48
64
  EnforcedStyle: consistent
49
65
 
50
- Layout/AlignParameters:
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/IndentArray:
107
+ Layout/IndentFirstArrayElement:
88
108
  EnforcedStyle: consistent
89
109
 
90
- Layout/IndentHash:
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
- Lint/BlockAlignment:
149
+ Layout/BlockAlignment:
130
150
  EnforcedStyleAlignWith: start_of_block
131
- #EnforcedStyleAlignWith: start_of_line
132
151
 
133
- Lint/EndAlignment:
152
+ Layout/EndAlignment:
134
153
  EnforcedStyleAlignWith: start_of_line
135
154
 
136
- Lint/DefEndAlignment:
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
@@ -11,20 +11,12 @@ branches:
11
11
  - master
12
12
  - develop
13
13
 
14
- env:
15
- global:
16
- - CC_TEST_REPORTER_ID=65e5bfcf0bfc99d25884678a632843ef1c294493b2581c2cf72b1cebfdc9d9fb
17
-
18
14
  before_install: gem install bundler
19
15
 
20
- before_script:
21
- - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
22
- - chmod +x ./cc-test-reporter
23
- - ./cc-test-reporter before-build
24
-
25
16
  script:
26
17
  - bundle exec rspec --order=random
27
18
 
28
- after_script:
29
- - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT || true
30
-
19
+ matrix:
20
+ include:
21
+ - rvm: ruby-head
22
+ script: bundle exec rubocop
data/README.md CHANGED
@@ -1,8 +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
- [![Maintainability](https://api.codeclimate.com/v1/badges/1768a558bf69d2f40681/maintainability)](https://codeclimate.com/github/mlibrary/canister/maintainability)
5
- [![Test Coverage](https://api.codeclimate.com/v1/badges/1768a558bf69d2f40681/test_coverage)](https://codeclimate.com/github/mlibrary/canister/test_coverage)
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)
6
6
 
7
7
  ## Summary
8
8
 
@@ -82,10 +82,11 @@ Standard rules apply.
82
82
 
83
83
  ## Compatibility
84
84
 
85
- * ruby 2.3.x
86
- * ruby 2.4.x
87
- * ruby 2.5.x
88
- * ruby 2.6.x
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)
89
90
 
90
91
  As Canister does not rely on any specific runtime environment other than
91
92
  the ruby core, it is compatible with every ruby library and framework.
data/canister.gemspec CHANGED
@@ -26,8 +26,10 @@ Gem::Specification.new do |spec|
26
26
  spec.require_paths = ["lib"]
27
27
 
28
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 "simplecov"
33
+ spec.add_development_dependency "rubocop-performance"
34
+ spec.add_development_dependency "rubocop-rspec"
33
35
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Canister
4
- VERSION = "0.9.1"
4
+ VERSION = "0.9.2"
5
5
  end
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
- invalidate(key) if registered?(key)
47
- registry[key.to_sym] = block
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
- add_dependent(key)
56
- stack << key
57
- value = resolved[key.to_sym] ||= registry[key.to_sym].call(self)
58
- stack.pop
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.to_sym] << stack.last
93
+ dependents[key] << stack.last
78
94
  end
79
95
  end
80
96
 
81
97
  def registered?(key)
82
- registry.key?(key.to_sym)
98
+ registry.key?(key)
83
99
  end
84
100
 
85
101
  def unresolve(key)
86
- resolved.delete(key.to_sym)
102
+ resolved.delete(key)
87
103
  end
88
104
 
89
105
  def invalidate(key, first = true)
90
106
  unresolve(key)
91
- dependents[key.to_sym]
107
+ dependents[key]
92
108
  .each {|child| invalidate(child, false) }
93
- dependents.delete(key.to_sym) if first
109
+ if first
110
+ dependents.delete(key)
111
+ end
94
112
  end
95
113
 
96
114
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: canister
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
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: 2019-01-23 00:00:00.000000000 Z
11
+ date: 2023-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
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
+ - - ">="
39
+ - !ruby/object:Gem::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: simplecov
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,8 +149,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
149
  - !ruby/object:Gem::Version
122
150
  version: '0'
123
151
  requirements: []
124
- rubygems_version: 3.0.2
125
- signing_key:
152
+ rubygems_version: 3.3.7
153
+ signing_key:
126
154
  specification_version: 4
127
155
  summary: A simple IoC container for ruby.
128
156
  test_files: []