isolator 0.3.0 → 0.4.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 +5 -0
- data/README.md +23 -2
- data/isolator.gemspec +1 -1
- data/lib/isolator/ignorer.rb +39 -0
- data/lib/isolator/isolate.rb +1 -1
- data/lib/isolator/railtie.rb +2 -0
- data/lib/isolator/version.rb +1 -1
- data/lib/isolator.rb +2 -0
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f375e040a8810bf83286b3bd78172a5b3e17504c21dc71d74dcc09b6313427d
|
4
|
+
data.tar.gz: faf57a3cc344a2fb889cc0ba87a1b47b33514330247b5d44574cf765e763c451
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4136572ecead2ed8eaef576958c317ef2ff42d8502a9caa04c974ca1ce5e5661231c42dfa83039e81d6cca45e13926115709c61223d381e42e83bf24f8ca9395
|
7
|
+
data.tar.gz: 42de6787f0c17d7b5da48be6b465479a37b4e20e7590cafaf261edf5f0ca29a9a341d451dfb6293aacb7e9958d0e47cf3aefcd53c77c900fe5ff3e04de15de6e
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,10 @@
|
|
2
2
|
|
3
3
|
## master
|
4
4
|
|
5
|
+
## 0.4.0 (2018-06-15)
|
6
|
+
|
7
|
+
- [PR [#13](https://github.com/palkan/isolator/pull/13)] Allow load ignored offences from YML file using `load_ignore_config`. ([@DmitryTsepelev][])
|
8
|
+
|
5
9
|
## 0.3.0 (2018-04-02)
|
6
10
|
|
7
11
|
- Add support for the [database_cleaner](https://github.com/DatabaseCleaner/database_cleaner) gem. ([@Envek][])
|
@@ -42,3 +46,4 @@
|
|
42
46
|
[@TheSmartnik]: https://github.com/TheSmartnik
|
43
47
|
[@dsalahutdinov]: https://github.com/dsalahutdinov
|
44
48
|
[@Envek]: https://github.com/Envek
|
49
|
+
[@DmitryTsepelev]: https://github.com/DmitryTsepelev
|
data/README.md
CHANGED
@@ -131,6 +131,10 @@ Isolator.adapters.http.disable!
|
|
131
131
|
Isolator.adapters.http.enable!
|
132
132
|
```
|
133
133
|
|
134
|
+
### Fix Offenses
|
135
|
+
|
136
|
+
For the actions that should be executed only after successful transaction commit (which is mostly always so), you can try to use the `after_commit` callback from [after_commit_everywhere] gem (or use native AR callback in models if it's applicable).
|
137
|
+
|
134
138
|
### Ignore Offenses
|
135
139
|
|
136
140
|
Since Isolator adapter is just a wrapper over original code, it may lead to false positives when there is another library patching the same behaviour. In that case you might want to ignore some offenses.
|
@@ -145,6 +149,22 @@ Isolator.adapters.sidekiq.ignore_if { Thread.current[:sidekiq_postpone] }
|
|
145
149
|
|
146
150
|
You can add as many _ignores_ as you want, the offense is registered iff all of them return false.
|
147
151
|
|
152
|
+
### Using with legacy Rails codebases
|
153
|
+
|
154
|
+
If you already have a huge Rails project it can be a tricky to turn Isolator on because you'll immediately get a lot of failed specs. If you want to fix detected issues one by one, you can list all of them in the special file `.isolator_todo.yml` in a following way:
|
155
|
+
|
156
|
+
```
|
157
|
+
sidekiq:
|
158
|
+
- app/models/user.rb:20
|
159
|
+
- app/models/sales/**/*.rb
|
160
|
+
```
|
161
|
+
|
162
|
+
All the exceptions raised in the listed lines will be ignored.
|
163
|
+
|
164
|
+
### Using with legacy Ruby codebases
|
165
|
+
|
166
|
+
If you are not using Rails, you'll have to load ignores from file manually, using `Isolator#load_ignore_config`, for instance `Isolator.load_ignore_config("./config/.isolator_todo.yml")`
|
167
|
+
|
148
168
|
## Custom Adapters
|
149
169
|
|
150
170
|
An adapter is just a combination of a _method wrapper_ and lifecycle hooks.
|
@@ -157,10 +177,10 @@ Suppose that you have a class `Danger` with a method `#explode`, which is not sa
|
|
157
177
|
#
|
158
178
|
# The second argument is the method owner and
|
159
179
|
# the third one is a method name.
|
160
|
-
|
180
|
+
Isolator.isolate :danger, Danger, :explode, options
|
161
181
|
|
162
182
|
# NOTE: if you want to isolate a class method, use signleton_class instead
|
163
|
-
Isolator.isolate :danger, Danger.singleton_class, :explode,
|
183
|
+
Isolator.isolate :danger, Danger.singleton_class, :explode, options
|
164
184
|
```
|
165
185
|
|
166
186
|
Possible `options` are:
|
@@ -189,3 +209,4 @@ The gem is available as open source under the terms of the [MIT License](http://
|
|
189
209
|
|
190
210
|
[Sniffer]: https://github.com/aderyabin/sniffer
|
191
211
|
[uniform_notifier]: https://github.com/flyerhzm/uniform_notifier
|
212
|
+
[after_commit_everywhere]: https://github.com/Envek/after_commit_everywhere
|
data/isolator.gemspec
CHANGED
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.add_development_dependency "rspec", "~> 3.0"
|
28
28
|
spec.add_development_dependency "rspec-rails", "~> 3.0"
|
29
29
|
spec.add_development_dependency "minitest", "~> 5.10.0"
|
30
|
-
spec.add_development_dependency "rubocop", "~> 0.
|
30
|
+
spec.add_development_dependency "rubocop", "~> 0.56.0"
|
31
31
|
spec.add_development_dependency "rubocop-md", "~> 0.2"
|
32
32
|
|
33
33
|
spec.add_development_dependency "uniform_notifier", "~> 1.11"
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Isolator
|
4
|
+
# Add .load_ignore_config function for ignoring patterns from file
|
5
|
+
module Ignorer
|
6
|
+
def load_ignore_config(path)
|
7
|
+
return unless File.exist?(path)
|
8
|
+
|
9
|
+
todos = YAML.load_file(path)
|
10
|
+
|
11
|
+
adapters.each do |id, adapter|
|
12
|
+
ignored_paths = todos.fetch(id, [])
|
13
|
+
configure_adapter(adapter, ignored_paths)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def configure_adapter(adapter, ignored_paths)
|
20
|
+
ignores = build_ignore_list(ignored_paths)
|
21
|
+
return if ignores.blank?
|
22
|
+
|
23
|
+
regex = Regexp.new("^.*(#{ignores.join('|')}):.*$")
|
24
|
+
adapter.ignore_if { caller.any? { |row| regex =~ row } }
|
25
|
+
end
|
26
|
+
|
27
|
+
def build_ignore_list(ignored_paths)
|
28
|
+
ignored_paths.each_with_object([]) do |path, result|
|
29
|
+
ignored_files = Dir[path]
|
30
|
+
|
31
|
+
if ignored_files.blank?
|
32
|
+
result << path.to_s
|
33
|
+
else
|
34
|
+
result.concat(ignored_files)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/isolator/isolate.rb
CHANGED
@@ -5,7 +5,7 @@ module Isolator
|
|
5
5
|
module Isolate
|
6
6
|
def isolate(id, **options)
|
7
7
|
raise "Adapter already registered: #{id}" if Isolator.adapters.key?(id.to_s)
|
8
|
-
adapter = AdapterBuilder.call(
|
8
|
+
adapter = AdapterBuilder.call(options)
|
9
9
|
Isolator.adapters[id.to_s] = adapter
|
10
10
|
end
|
11
11
|
end
|
data/lib/isolator/railtie.rb
CHANGED
data/lib/isolator/version.rb
CHANGED
data/lib/isolator.rb
CHANGED
@@ -6,6 +6,7 @@ require "isolator/adapter_builder"
|
|
6
6
|
require "isolator/notifier"
|
7
7
|
require "isolator/errors"
|
8
8
|
require "isolator/simple_hashie"
|
9
|
+
require "isolator/ignorer"
|
9
10
|
|
10
11
|
require "isolator/callbacks"
|
11
12
|
require "isolator/isolate"
|
@@ -105,6 +106,7 @@ module Isolator
|
|
105
106
|
|
106
107
|
include Isolator::Isolate
|
107
108
|
include Isolator::Callbacks
|
109
|
+
include Isolator::Ignorer
|
108
110
|
end
|
109
111
|
end
|
110
112
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: isolator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vladimir Dementyev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-06-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sniffer
|
@@ -100,14 +100,14 @@ dependencies:
|
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version:
|
103
|
+
version: 0.56.0
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version:
|
110
|
+
version: 0.56.0
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: rubocop-md
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -290,6 +290,7 @@ files:
|
|
290
290
|
- lib/isolator/database_cleaner_support.rb
|
291
291
|
- lib/isolator/errors.rb
|
292
292
|
- lib/isolator/ext/thread_fetch.rb
|
293
|
+
- lib/isolator/ignorer.rb
|
293
294
|
- lib/isolator/isolate.rb
|
294
295
|
- lib/isolator/notifier.rb
|
295
296
|
- lib/isolator/orm_adapters.rb
|
@@ -319,7 +320,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
319
320
|
version: '0'
|
320
321
|
requirements: []
|
321
322
|
rubyforge_project:
|
322
|
-
rubygems_version: 2.7.
|
323
|
+
rubygems_version: 2.7.6
|
323
324
|
signing_key:
|
324
325
|
specification_version: 4
|
325
326
|
summary: Detect non-atomic interactions within DB transactions
|