activerecord-transactionable 2.0.4 → 2.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/FUNDING.yml +12 -0
- data/.github/dependabot.yml +8 -0
- data/.github/workflows/eol.yml +37 -0
- data/.github/workflows/style.yml +34 -0
- data/.github/workflows/supported.yml +57 -0
- data/.github/workflows/unsupported.yml +40 -0
- data/.gitignore +2 -1
- data/.rspec +1 -0
- data/.rubocop.yml +121 -4
- data/.rubocop_todo.yml +138 -0
- data/.simplecov +5 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/CONTRIBUTING.md +26 -0
- data/Gemfile +3 -13
- data/LICENSE +18 -4
- data/README.md +118 -37
- data/Rakefile +22 -3
- data/SECURITY.md +14 -0
- data/activerecord-transactionable.gemspec +49 -21
- data/bin/console +4 -3
- data/lib/activerecord/transactionable/result.rb +13 -10
- data/lib/activerecord/transactionable/version.rb +3 -1
- data/lib/activerecord/transactionable.rb +65 -53
- metadata +206 -37
- data/.coveralls.yml +0 -1
- data/.travis.yml +0 -50
- data/Appraisals +0 -34
- data/gemfiles/rails_4_0.gemfile +0 -9
- data/gemfiles/rails_4_1.gemfile +0 -9
- data/gemfiles/rails_4_2.gemfile +0 -9
- data/gemfiles/rails_5_0.gemfile +0 -9
- data/gemfiles/rails_5_1.gemfile +0 -9
- data/gemfiles/rails_5_2.gemfile +0 -9
data/README.md
CHANGED
@@ -2,23 +2,15 @@
|
|
2
2
|
|
3
3
|
Provides a method, `transaction_wrapper` at the class and instance levels that can be used instead of `ActiveRecord#transaction`. Enables you to do transactions properly, with custom rescues and retry, including with or without locking.
|
4
4
|
|
5
|
-
| Project
|
6
|
-
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
| code quality | [![Maintainability](https://api.codeclimate.com/v1/badges/41fa99881cfe6d45e7e5/maintainability)](https://codeclimate.com/github/pboling/activerecord-transactionable/maintainability) |
|
15
|
-
| code triage | [![Open Source Helpers](https://www.codetriage.com/pboling/activerecord-transactionable/badges/users.svg)](https://www.codetriage.com/pboling/activerecord-transactionable) |
|
16
|
-
| inline documenation | [![Inline docs](http://inch-ci.org/github/pboling/activerecord-transactionable.png)](http://inch-ci.org/github/pboling/activerecord-transactionable) |
|
17
|
-
| homepage | [on Github.com][homepage], [on Railsbling.com][blogpage] |
|
18
|
-
| documentation | [on RDoc.info][documentation] |
|
19
|
-
| live chat | [![Join the chat at https://gitter.im/pboling/activerecord-transactionable](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/pboling/activerecord-transactionable?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) |
|
20
|
-
| expert support | [![Get help on Codementor](https://cdn.codementor.io/badges/get_help_github.svg)](https://www.codementor.io/peterboling?utm_source=github&utm_medium=button&utm_term=peterboling&utm_campaign=github) |
|
21
|
-
| Spread ~♡ⓛⓞⓥⓔ♡~ | [🌍 🌎 🌏](https://about.me/peter.boling), [🍚](https://www.crowdrise.com/helprefugeeswithhopefortomorrowliberia/fundraiser/peterboling), [➕](https://plus.google.com/+PeterBoling/posts), [👼](https://angel.co/peter-boling), [🐛](https://www.topcoder.com/members/pboling/), [:shipit:](http://coderwall.com/pboling), [![Tweet Peter](https://img.shields.io/twitter/follow/galtzo.svg?style=social&label=Follow)](http://twitter.com/galtzo) |
|
5
|
+
| Project | Activerecord::Transactionable |
|
6
|
+
|--------------------------- |--------------------------- |
|
7
|
+
| name, license, docs | [`activerecord-transactionable`][rubygems] [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)][license-ref] [![RubyDoc.info](https://img.shields.io/badge/documentation-rubydoc-brightgreen.svg?style=flat)][documentation] |
|
8
|
+
| version & downloads | [![Version](https://img.shields.io/gem/v/activerecord-transactionable.svg)][rubygems] [![Total Downloads](https://img.shields.io/gem/dt/activerecord-transactionable.svg)][rubygems] [![Downloads Today](https://img.shields.io/gem/rd/activerecord-transactionable.svg)][rubygems] [![Homepage](https://img.shields.io/badge/source-github-brightgreen.svg?style=flat)][source] |
|
9
|
+
| dependencies & linting | [![Depfu](https://badges.depfu.com/badges/d570491bac0ad3b0b65deb3c82028327/count.svg)][depfu] [![lint status](https://github.com/pboling/activerecord-transactionable/actions/workflows/style.yml/badge.svg)][actions] |
|
10
|
+
| unit tests | [![supported rubies](https://github.com/pboling/activerecord-transactionable/actions/workflows/supported.yml/badge.svg)][actions] [![unsupported status](https://github.com/pboling/activerecord-transactionable/actions/workflows/unsupported.yml/badge.svg)][actions] |
|
11
|
+
| coverage & maintainability | [![Test Coverage](https://api.codeclimate.com/v1/badges/41fa99881cfe6d45e7e5/test_coverage)][climate_coverage] [![codecov](https://codecov.io/gh/pboling/activerecord-transactionable/branch/master/graph/badge.svg?token=4ZNAWNxrf9)][codecov_coverage] [![Maintainability](https://api.codeclimate.com/v1/badges/41fa99881cfe6d45e7e5/maintainability)][climate_maintainability] [![Maintenance Policy](https://img.shields.io/badge/maintenance-policy-brightgreen.svg?style=flat)][maintenancee_policy] |
|
12
|
+
| resources | [![Discussion](https://img.shields.io/badge/discussions-github-brightgreen.svg?style=flat)][gh_discussions] [![Get help on Codementor](https://cdn.codementor.io/badges/get_help_github.svg)](https://www.codementor.io/peterboling?utm_source=github&utm_medium=button&utm_term=peterboling&utm_campaign=github) [![Join the chat at https://gitter.im/pboling/activerecord-transactionable](https://badges.gitter.im/Join%20Chat.svg)][chat] [![Blog](https://img.shields.io/badge/blog-railsbling-brightgreen.svg?style=flat)][blogpage] |
|
13
|
+
| Spread ~♡ⓛⓞⓥⓔ♡~ | [![Open Source Helpers](https://www.codetriage.com/pboling/activerecord-transactionable/badges/users.svg)][code_triage] [![Liberapay Patrons](https://img.shields.io/liberapay/patrons/pboling.svg?logo=liberapay)][liberapay_donate] [![Sponsor Me](https://img.shields.io/badge/sponsor-pboling.svg?style=social&logo=github)][gh_sponsors] [🌏][aboutme] [👼][angelme] [💻][coderme] [🌹][politicme] [![Tweet @ Peter][followme-img]][tweetme] |
|
22
14
|
|
23
15
|
Useful as an example of correct behavior for wrapping transactions.
|
24
16
|
|
@@ -27,13 +19,15 @@ NOTE: Rails' transactions are per-database connection, not per-model, nor per-in
|
|
27
19
|
|
28
20
|
## Upgrading to Version 2
|
29
21
|
|
30
|
-
In version 1 the `transaction_wrapper` returned `true` or `false`. In version 2 it returns an instance of `Activerecord::Transactionable::Result`, which has a `value`, and
|
22
|
+
In version 1 the `transaction_wrapper` returned `true` or `false`. In version 2 it returns an instance of `Activerecord::Transactionable::Result`, which has a `value`, and three methods:
|
31
23
|
```ruby
|
32
|
-
|
24
|
+
args = {}
|
25
|
+
result = transaction_wrapper(**args) do
|
33
26
|
something
|
34
27
|
end
|
35
28
|
result.fail?
|
36
29
|
result.success?
|
30
|
+
result.to_h # => a hash with diagnostic information, particularly useful when things go wrong
|
37
31
|
```
|
38
32
|
Where you used to have:
|
39
33
|
```ruby
|
@@ -53,7 +47,7 @@ end
|
|
53
47
|
Add this line to your application's Gemfile:
|
54
48
|
|
55
49
|
```ruby
|
56
|
-
gem
|
50
|
+
gem "activerecord-transactionable"
|
57
51
|
```
|
58
52
|
|
59
53
|
And then execute:
|
@@ -64,6 +58,19 @@ Or install it yourself as:
|
|
64
58
|
|
65
59
|
$ gem install activerecord-transactionable
|
66
60
|
|
61
|
+
## Compatibility
|
62
|
+
|
63
|
+
Targeted ruby compatibility is non-EOL versions of Ruby, currently 2.6, 2.7, and
|
64
|
+
3.0. Ruby is limited to 2.1+ in the gemspec, and when it changes there will be a major release.
|
65
|
+
The `master` branch currently targets 2.0.x releases.
|
66
|
+
|
67
|
+
| Ruby OAuth Version | Maintenance Branch | Officially Supported Rubies | Unofficially Supported Rubies |
|
68
|
+
|--------------------- | ------------------ | ------------------------------------------- | ----------------------------- |
|
69
|
+
| 3.0.x | N/A | 2.7, 3.0, 3.1 | 2.6 |
|
70
|
+
| 2.0.x | `master` | 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 3.0 | |
|
71
|
+
|
72
|
+
NOTE: 2.0.5 is anticipated as last release of the 2.x series.
|
73
|
+
|
67
74
|
## Usage
|
68
75
|
|
69
76
|
```ruby
|
@@ -118,7 +125,7 @@ If you need to know if the transaction succeeded:
|
|
118
125
|
car = Car.new(name: nil)
|
119
126
|
result = car.transaction_wrapper(lock: true) do # uses ActiveRecord's with_lock
|
120
127
|
car.save!
|
121
|
-
|
128
|
+
end
|
122
129
|
result # => an instance of Activerecord::Transactionable::Result
|
123
130
|
result.success? # => true or false
|
124
131
|
```
|
@@ -127,10 +134,10 @@ result.success? # => true or false
|
|
127
134
|
|
128
135
|
```ruby
|
129
136
|
@client = Client.find(params[:id])
|
130
|
-
transaction_result =
|
137
|
+
transaction_result = @client.transaction_wrapper(lock: true) do
|
131
138
|
@client.assign_attributes(client_params)
|
132
139
|
@client.save!
|
133
|
-
|
140
|
+
end
|
134
141
|
if transaction_result.success?
|
135
142
|
render :show, locals: { client: @client }, status: :ok
|
136
143
|
else
|
@@ -183,8 +190,8 @@ module SendToRaygun
|
|
183
190
|
begin
|
184
191
|
Raygun.track_exception(args[:error])
|
185
192
|
Rails.logger.debug("Sent Error to Raygun: #{args[:error].class}: #{args[:error].message}")
|
186
|
-
rescue => e
|
187
|
-
Rails.logger.
|
193
|
+
rescue StandardError => e
|
194
|
+
Rails.logger.error("Sending Error #{args[:error].class}: #{args[:error].message} to Raygun Failed with: #{e.class}: #{e.message}")
|
188
195
|
end
|
189
196
|
end
|
190
197
|
end
|
@@ -195,6 +202,17 @@ Activerecord::Transactionable::ClassMethods.class_eval do
|
|
195
202
|
end
|
196
203
|
```
|
197
204
|
|
205
|
+
## More Information
|
206
|
+
|
207
|
+
* RubyDoc Documentation: [![RubyDoc.info](https://img.shields.io/badge/documentation-rubydoc-brightgreen.svg?style=flat)][documentation]
|
208
|
+
* GitHub Discussions: [![Discussion](https://img.shields.io/badge/discussions-github-brightgreen.svg?style=flat)][gh_discussions]
|
209
|
+
* Live Chat on Gitter: [![Join the chat at https://gitter.im/pboling/activerecord-transactionable](https://badges.gitter.im/Join%20Chat.svg)][chat]
|
210
|
+
* Maintainer's Blog: [![Blog](https://img.shields.io/badge/blog-railsbling-brightgreen.svg?style=flat)][blogpage]
|
211
|
+
|
212
|
+
## Code of Conduct
|
213
|
+
|
214
|
+
Everyone interacting with this project's code, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/pboling/activerecord-transactionable/blob/master/CODE_OF_CONDUCT.md).
|
215
|
+
|
198
216
|
## Development
|
199
217
|
|
200
218
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -203,11 +221,11 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
203
221
|
|
204
222
|
## Contributing
|
205
223
|
|
206
|
-
|
224
|
+
See [CONTRIBUTING.md][contributing]
|
207
225
|
|
208
|
-
##
|
226
|
+
## Contributors
|
209
227
|
|
210
|
-
|
228
|
+
[![Contributors](https://contrib.rocks/image?repo=pboling/activerecord-transactionable)][contributors]
|
211
229
|
|
212
230
|
## Versioning
|
213
231
|
|
@@ -224,24 +242,87 @@ dependency on this gem using the [Pessimistic Version Constraint][pvc] with two
|
|
224
242
|
For example:
|
225
243
|
|
226
244
|
```ruby
|
227
|
-
spec.add_dependency
|
245
|
+
spec.add_dependency "activerecord-transactionable", "~> 2.0"
|
228
246
|
```
|
229
247
|
|
230
|
-
##
|
248
|
+
## License
|
231
249
|
|
232
|
-
|
250
|
+
* Copyright (c) 2016 - 2018, 2021 [Peter H. Boling][peterboling] of [Rails Bling][railsbling]
|
233
251
|
|
234
|
-
|
252
|
+
[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)][license-ref]
|
235
253
|
|
236
|
-
|
254
|
+
[copyright-notice-explainer]: https://opensource.stackexchange.com/questions/5778/why-do-licenses-such-as-the-mit-license-specify-a-single-year
|
237
255
|
|
238
|
-
[
|
256
|
+
[license]: https://github.com/pboling/activerecord-transactionable/blob/master/LICENSE
|
239
257
|
|
240
|
-
[license]: LICENSE
|
241
258
|
[semver]: http://semver.org/
|
259
|
+
|
242
260
|
[pvc]: http://guides.rubygems.org/patterns/#pessimistic-version-constraint
|
261
|
+
|
243
262
|
[railsbling]: http://www.railsbling.com
|
263
|
+
|
244
264
|
[peterboling]: http://www.peterboling.com
|
245
|
-
|
246
|
-
[
|
265
|
+
|
266
|
+
[issues]: https://github.com/pboling/activerecord-transactionable/issues
|
267
|
+
|
268
|
+
[contributing]: https://github.com/pboling/activerecord-transactionable/blob/master/CONTRIBUTING.md
|
269
|
+
|
270
|
+
[comment]: <> (Following links are used by README, CONTRIBUTING)
|
271
|
+
|
272
|
+
[contributors]: https://github.com/pboling/activerecord-transactionable/graphs/contributors
|
273
|
+
|
274
|
+
[comment]: <> (Following links are used by README, CONTRIBUTING, Homepage)
|
275
|
+
|
276
|
+
[mailinglist]: http://groups.google.com/group/activerecord-transactionable-ruby
|
277
|
+
|
278
|
+
[source]: https://github.com/pboling/activerecord-transactionable/
|
279
|
+
|
280
|
+
[comment]: <> (Following links are used by Homepage)
|
281
|
+
|
282
|
+
[network]: https://github.com/pboling/activerecord-transactionable/network
|
283
|
+
|
284
|
+
[stargazers]: https://github.com/pboling/activerecord-transactionable/stargazers
|
285
|
+
|
286
|
+
[comment]: <> (Following links are used by README, Homepage)
|
287
|
+
|
288
|
+
[rubygems]: https://rubygems.org/gems/activerecord-transactionable
|
289
|
+
|
290
|
+
[depfu]: https://depfu.com/github/pboling/activerecord-transactionable?project_id=2653
|
291
|
+
|
292
|
+
[actions]: https://github.com/pboling/activerecord-transactionable/actions
|
293
|
+
|
294
|
+
[climate_coverage]: https://codeclimate.com/github/pboling/activerecord-transactionable/test_coverage
|
295
|
+
|
296
|
+
[gh_discussions]: https://github.com/pboling/activerecord-transactionable/discussions
|
297
|
+
|
298
|
+
[code_triage]: https://www.codetriage.com/pboling/activerecord-transactionable
|
299
|
+
|
300
|
+
[license-ref]: https://opensource.org/licenses/MIT
|
301
|
+
|
302
|
+
[codecov_coverage]: https://codecov.io/gh/pboling/activerecord-transactionable
|
303
|
+
|
304
|
+
[liberapay_donate]: https://liberapay.com/pboling/donate
|
305
|
+
|
306
|
+
[aboutme]: https://about.me/peter.boling
|
307
|
+
|
308
|
+
[angelme]: https://angel.co/peter-boling
|
309
|
+
|
310
|
+
[coderme]:http://coderwall.com/pboling
|
311
|
+
|
312
|
+
[politicme]: https://nationalprogressiveparty.org
|
313
|
+
|
314
|
+
[followme-img]: https://img.shields.io/twitter/follow/galtzo.svg?style=social&label=Follow
|
315
|
+
|
316
|
+
[tweetme]: http://twitter.com/galtzo
|
317
|
+
|
318
|
+
[documentation]: https://rubydoc.info/github/pboling/activerecord-transactionable
|
319
|
+
|
320
|
+
[climate_maintainability]: https://codeclimate.com/github/pboling/activerecord-transactionable/maintainability
|
321
|
+
|
322
|
+
[chat]: https://gitter.im/pboling/activerecord-transactionable?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
|
323
|
+
|
247
324
|
[blogpage]: http://www.railsbling.com/tags/activerecord-transactionable/
|
325
|
+
|
326
|
+
[maintenancee_policy]: https://guides.rubyonrails.org/maintenance_policy.html#security-issues
|
327
|
+
|
328
|
+
[gh_sponsors]: https://github.com/sponsors/pboling
|
data/Rakefile
CHANGED
@@ -1,6 +1,25 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
%w[
|
4
|
+
bundler/gem_tasks
|
5
|
+
rake/testtask
|
6
|
+
rspec/core/rake_task
|
7
|
+
fileutils
|
8
|
+
].each { |f| require f }
|
9
|
+
|
10
|
+
Bundler::GemHelper.install_tasks
|
3
11
|
|
4
12
|
RSpec::Core::RakeTask.new(:spec)
|
13
|
+
desc "alias spec => test"
|
14
|
+
task test: :spec
|
15
|
+
|
16
|
+
begin
|
17
|
+
require "rubocop/rake_task"
|
18
|
+
RuboCop::RakeTask.new
|
19
|
+
rescue LoadError
|
20
|
+
task :rubocop do
|
21
|
+
warn "RuboCop is disabled on Ruby #{RUBY_VERSION}"
|
22
|
+
end
|
23
|
+
end
|
5
24
|
|
6
|
-
task default:
|
25
|
+
task default: %i[spec rubocop]
|
data/SECURITY.md
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# Security Policy
|
2
|
+
|
3
|
+
## Supported Versions
|
4
|
+
|
5
|
+
| Version | Supported |
|
6
|
+
| ------- | ------------------ |
|
7
|
+
| 3.0.x | :white_check_mark: |
|
8
|
+
| 2.0.x | :white_check_mark: |
|
9
|
+
| 1.0.x | :x: |
|
10
|
+
| 0.0.x | :x: |
|
11
|
+
|
12
|
+
## Reporting a Vulnerability
|
13
|
+
|
14
|
+
Peter Boling is the primary maintainer of this gem. Please find a way to [contact him directly](https://railsbling.com/contact) to report the issue. Include as much relevant information as possible.
|
@@ -1,32 +1,60 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path("lib", __dir__)
|
2
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
-
require
|
5
|
+
require "activerecord/transactionable/version"
|
4
6
|
|
5
7
|
Gem::Specification.new do |spec|
|
6
|
-
spec.name =
|
8
|
+
spec.name = "activerecord-transactionable"
|
7
9
|
spec.version = Activerecord::Transactionable::VERSION
|
8
|
-
spec.authors = [
|
9
|
-
spec.email = [
|
10
|
-
spec.licenses = [
|
10
|
+
spec.authors = ["Peter Boling"]
|
11
|
+
spec.email = ["peter.boling@gmail.com"]
|
12
|
+
spec.licenses = ["MIT"]
|
11
13
|
|
12
|
-
spec.summary =
|
13
|
-
spec.description =
|
14
|
-
spec.homepage =
|
14
|
+
spec.summary = "Do ActiveRecord transactions the right way."
|
15
|
+
spec.description = "Getting transactions right is hard, and this gem makes it easier."
|
16
|
+
spec.homepage = "http://www.railsbling.com/tags/activerecord-transactionable"
|
15
17
|
|
16
18
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
-
spec.bindir =
|
19
|
+
spec.bindir = "exe"
|
18
20
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
-
spec.require_paths = [
|
20
|
-
spec.required_ruby_version =
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
spec.required_ruby_version = ">= 2.1.0"
|
23
|
+
|
24
|
+
ruby_version = Gem::Version.new(RUBY_VERSION)
|
25
|
+
minimum_version = ->(version) { ruby_version >= Gem::Version.new(version) && RUBY_ENGINE == "ruby" }
|
26
|
+
linting = minimum_version.call("2.6")
|
27
|
+
coverage = minimum_version.call("2.6")
|
28
|
+
good_sqlite_constraint = minimum_version.call("2.5")
|
29
|
+
debug = minimum_version.call("2.4")
|
21
30
|
|
22
|
-
spec.add_dependency
|
23
|
-
spec.add_dependency
|
31
|
+
spec.add_dependency "activemodel", ">= 4.0.0"
|
32
|
+
spec.add_dependency "activerecord", ">= 4.0.0"
|
24
33
|
|
25
|
-
spec.add_development_dependency
|
26
|
-
spec.add_development_dependency
|
27
|
-
spec.add_development_dependency
|
28
|
-
spec.add_development_dependency
|
29
|
-
spec.add_development_dependency
|
30
|
-
spec.add_development_dependency
|
31
|
-
spec.add_development_dependency
|
34
|
+
spec.add_development_dependency "byebug", "~> 11.1" if debug
|
35
|
+
spec.add_development_dependency "factory_bot", ">= 4.0"
|
36
|
+
spec.add_development_dependency "rake", ">= 12.0"
|
37
|
+
spec.add_development_dependency "rspec", "~> 3.10"
|
38
|
+
spec.add_development_dependency "rspec-benchmark", "~> 0.6"
|
39
|
+
spec.add_development_dependency "rspec-block_is_expected", "~> 1.0"
|
40
|
+
spec.add_development_dependency "rspec-pending_for", "~> 0.1"
|
41
|
+
if linting
|
42
|
+
spec.add_development_dependency("rubocop", "~> 1.22")
|
43
|
+
spec.add_development_dependency("rubocop-md", "~> 1.0")
|
44
|
+
spec.add_development_dependency("rubocop-minitest", "~> 0.15")
|
45
|
+
spec.add_development_dependency("rubocop-packaging", "~> 0.5")
|
46
|
+
spec.add_development_dependency("rubocop-performance", "~> 1.11")
|
47
|
+
spec.add_development_dependency("rubocop-rake", "~> 0.6")
|
48
|
+
spec.add_development_dependency("rubocop-rspec", "~> 2.5")
|
49
|
+
spec.add_development_dependency("rubocop-thread_safety", "~> 0.4")
|
50
|
+
end
|
51
|
+
if coverage
|
52
|
+
spec.add_development_dependency("simplecov", "~> 0.21")
|
53
|
+
spec.add_development_dependency("simplecov-cobertura", "~> 1.4")
|
54
|
+
end
|
55
|
+
# sqlite version constraint: https://stackoverflow.com/a/54729071/213191
|
56
|
+
# TODO: Relax and update the constraint when dropping support for <= activerecord 5.2.2
|
57
|
+
# NOTE: Ruby 2.5+ will install Rails 6+
|
58
|
+
spec.add_development_dependency "sqlite3", good_sqlite_constraint ? "~> 1" : "~> 1.3.6"
|
59
|
+
spec.add_development_dependency "yard", ">= 0.9.20"
|
32
60
|
end
|
data/bin/console
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
require
|
4
|
-
require
|
4
|
+
require "bundler/setup"
|
5
|
+
require "activerecord/transactionable"
|
5
6
|
|
6
7
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
8
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +11,5 @@ require 'activerecord/transactionable'
|
|
10
11
|
# require "pry"
|
11
12
|
# Pry.start
|
12
13
|
|
13
|
-
require
|
14
|
+
require "irb"
|
14
15
|
IRB.start
|
@@ -1,10 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Activerecord
|
2
4
|
module Transactionable
|
3
5
|
class Result
|
4
6
|
attr_reader :value, :result, :error, :type, :context, :nested, :attempt
|
7
|
+
|
5
8
|
def initialize(value, context:, transaction_open:, attempt:, error: nil, type: nil)
|
6
9
|
@value = value
|
7
|
-
@result = fail? ?
|
10
|
+
@result = fail? ? "fail" : "success"
|
8
11
|
@context = context
|
9
12
|
@nested = transaction_open ? true : false
|
10
13
|
@attempt = attempt
|
@@ -22,16 +25,16 @@ module Activerecord
|
|
22
25
|
|
23
26
|
def to_h(skip_error: nil)
|
24
27
|
diagnostic_data = {
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
28
|
+
result: result,
|
29
|
+
type: type,
|
30
|
+
context: context,
|
31
|
+
nested: nested,
|
32
|
+
attempt: attempt
|
30
33
|
}
|
31
|
-
|
32
|
-
error
|
33
|
-
message
|
34
|
-
|
34
|
+
if !skip_error && error
|
35
|
+
diagnostic_data[:error] = error.class.to_s
|
36
|
+
diagnostic_data[:message] = error.message
|
37
|
+
end
|
35
38
|
diagnostic_data
|
36
39
|
end
|
37
40
|
|