after_commit_everywhere 0.1.3 → 1.1.0

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: d959365a048625cd9a944d475f20a3621bcaba1666399f558269eee56ba6d238
4
- data.tar.gz: 17b9c71cb73cb8c86a3d45928476537169183dca86bdfd896eb7c66c83d32b7f
3
+ metadata.gz: 4425b11aa2651bd44ec24dc839e1338537f087f89c3f19f250d3ad2aeb0fad07
4
+ data.tar.gz: 143406ceecd3d9d3e1f7999f8cbb3754c19186036a7b2f47f19996c932048e26
5
5
  SHA512:
6
- metadata.gz: e453a9b961a9c5d18c77a0bb1d69fe899604b8970316459e008930ad0264c5a9077cf2adf7bf9ce6ecde856a1b5c8a1cf3a8f733e25a7e65d6641be8fc63aa8d
7
- data.tar.gz: 915d3541eaf4c43f0eb195cb94ea0debd86d3fa0372ad2eb081fa2471c2f80586fc96c9691bf77af15390522b8cf06e5aa2f82410cde6ef1f9bff5ed898fff1a
6
+ metadata.gz: fdaa287369af57e90b69699fdbd11b687491ea9c938af714e8a68871954b3685e07c4a9ba16939094ea6f082cec84ce351c9354341685f42bcd58bcc0307ee29
7
+ data.tar.gz: 5a42c24b63cbdf2d84597e3fa6071d588a76e8821736239a146708dd155a8492dc657c29577022d7072c13ecdcc4d0b1ee22243701d1e1058ebcd13ee6072573
@@ -0,0 +1,82 @@
1
+ name: Build and release gem
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - v*
7
+
8
+ jobs:
9
+ release:
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - uses: actions/checkout@v2
13
+ with:
14
+ fetch-depth: 0 # Fetch current tag as annotated. See https://github.com/actions/checkout/issues/290
15
+ - uses: ruby/setup-ruby@v1
16
+ with:
17
+ ruby-version: 2.7
18
+ - name: "Extract data from tag: version, message, body"
19
+ id: tag
20
+ run: |
21
+ git fetch --tags --force # Really fetch annotated tag. See https://github.com/actions/checkout/issues/290#issuecomment-680260080
22
+ echo ::set-output name=version::${GITHUB_REF#refs/tags/v}
23
+ echo ::set-output name=subject::$(git for-each-ref $GITHUB_REF --format='%(contents:subject)')
24
+ BODY="$(git for-each-ref $GITHUB_REF --format='%(contents:body)')"
25
+ # Extract changelog entries between this and previous version headers
26
+ escaped_version=$(echo ${GITHUB_REF#refs/tags/v} | sed -e 's/[]\/$*.^[]/\\&/g')
27
+ changelog=$(awk "BEGIN{inrelease=0} /## ${escaped_version}/{inrelease=1;next} /## [0-9]+\.[0-9]+\.[0-9]+/{inrelease=0;exit} {if (inrelease) print}" CHANGELOG.md)
28
+ # Multiline body for release. See https://github.community/t/set-output-truncates-multiline-strings/16852/5
29
+ BODY="${BODY}"$'\n'"${changelog}"
30
+ BODY="${BODY//'%'/'%25'}"
31
+ BODY="${BODY//$'\n'/'%0A'}"
32
+ BODY="${BODY//$'\r'/'%0D'}"
33
+ echo "::set-output name=body::$BODY"
34
+ # Add pre-release option if tag name has any suffix after vMAJOR.MINOR.PATCH
35
+ if [[ ${GITHUB_REF#refs/tags/} =~ ^v[0-9]+\.[0-9]+\.[0-9]+.+ ]]; then
36
+ echo ::set-output name=prerelease::true
37
+ fi
38
+ - name: Build gem
39
+ run: gem build
40
+ - name: Calculate checksums
41
+ run: sha256sum after_commit_everywhere-${{ steps.tag.outputs.version }}.gem > SHA256SUM
42
+ - name: Check version
43
+ run: ls -l after_commit_everywhere-${{ steps.tag.outputs.version }}.gem
44
+ - name: Create Release
45
+ id: create_release
46
+ uses: actions/create-release@v1
47
+ env:
48
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
49
+ with:
50
+ tag_name: ${{ github.ref }}
51
+ release_name: ${{ steps.tag.outputs.subject }}
52
+ body: ${{ steps.tag.outputs.body }}
53
+ draft: false
54
+ prerelease: ${{ steps.tag.outputs.prerelease }}
55
+ - name: Upload built gem as release asset
56
+ uses: actions/upload-release-asset@v1
57
+ env:
58
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
59
+ with:
60
+ upload_url: ${{ steps.create_release.outputs.upload_url }}
61
+ asset_path: after_commit_everywhere-${{ steps.tag.outputs.version }}.gem
62
+ asset_name: after_commit_everywhere-${{ steps.tag.outputs.version }}.gem
63
+ asset_content_type: application/x-tar
64
+ - name: Upload checksums as release asset
65
+ uses: actions/upload-release-asset@v1
66
+ env:
67
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
68
+ with:
69
+ upload_url: ${{ steps.create_release.outputs.upload_url }}
70
+ asset_path: SHA256SUM
71
+ asset_name: SHA256SUM
72
+ asset_content_type: text/plain
73
+ - name: Publish to GitHub packages
74
+ env:
75
+ GEM_HOST_API_KEY: Bearer ${{ secrets.GITHUB_TOKEN }}
76
+ run: |
77
+ gem push after_commit_everywhere-${{ steps.tag.outputs.version }}.gem --host https://rubygems.pkg.github.com/${{ github.repository_owner }}
78
+ - name: Publish to RubyGems
79
+ env:
80
+ GEM_HOST_API_KEY: "${{ secrets.RUBYGEMS_API_KEY }}"
81
+ run: |
82
+ gem push after_commit_everywhere-${{ steps.tag.outputs.version }}.gem
@@ -0,0 +1,63 @@
1
+ name: Run tests
2
+
3
+ on:
4
+ pull_request:
5
+ push:
6
+ branches:
7
+ - '**'
8
+ tags-ignore:
9
+ - 'v*'
10
+ schedule:
11
+ - cron: '42 0 1 * *' # on 1st day of every month at 00:42
12
+
13
+ jobs:
14
+ test:
15
+ name: 'ActiveRecord ${{ matrix.activerecord }} on Ruby ${{ matrix.ruby }}'
16
+ runs-on: ubuntu-latest
17
+ strategy:
18
+ fail-fast: false
19
+ matrix:
20
+ include:
21
+ - ruby: '2.5'
22
+ activerecord: '4.2'
23
+ gemfile: 'activerecord_4_2.gemfile'
24
+ - ruby: '2.6'
25
+ activerecord: '5.0'
26
+ gemfile: 'activerecord_5_0.gemfile'
27
+ - ruby: '2.6'
28
+ activerecord: '5.1'
29
+ gemfile: 'activerecord_5_1.gemfile'
30
+ - ruby: '2.6'
31
+ activerecord: '5.2'
32
+ gemfile: 'activerecord_5_2.gemfile'
33
+ - ruby: '2.7'
34
+ activerecord: '6.0'
35
+ gemfile: 'activerecord_6_0.gemfile'
36
+ - ruby: '2.7'
37
+ activerecord: '6.1'
38
+ gemfile: 'activerecord_6_1.gemfile'
39
+ - ruby: '3.0'
40
+ activerecord: 'HEAD'
41
+ gemfile: 'activerecord_master.gemfile'
42
+ container:
43
+ image: ruby:${{ matrix.ruby }}
44
+ env:
45
+ CI: true
46
+ BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}
47
+ steps:
48
+ - uses: actions/checkout@v2
49
+ - uses: actions/cache@v2
50
+ with:
51
+ path: vendor/bundle
52
+ key: bundle-${{ matrix.ruby }}-${{ hashFiles('**/*.gemspec') }}-${{ hashFiles('**/Gemfile') }}
53
+ restore-keys: |
54
+ bundle-${{ matrix.ruby }}-${{ hashFiles('**/*.gemspec') }}-${{ hashFiles('**/Gemfile') }}
55
+ bundle-${{ matrix.ruby }}-
56
+ - name: Upgrade Bundler to 2.x (mostly for Rubies older than 2.7)
57
+ run: gem install bundler -v '~> 2.0' -v '!= 2.2.10'
58
+ - name: Bundle install
59
+ run: |
60
+ bundle config path vendor/bundle
61
+ bundle update
62
+ - name: Run RSpec
63
+ run: bundle exec rspec
data/.gitignore CHANGED
@@ -6,7 +6,6 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
- Gemfile.lock
10
9
  /gemfiles/*.lock
11
10
 
12
11
  # rspec failure tracking
data/.rubocop.yml CHANGED
@@ -2,6 +2,8 @@ AllCops:
2
2
  TargetRubyVersion: 2.3
3
3
  UseCache: false
4
4
  DisplayCopNames: true
5
+ Exclude:
6
+ - "gemfiles/*"
5
7
 
6
8
  Metrics/LineLength:
7
9
  Max: 100
@@ -24,7 +26,7 @@ Metrics/BlockLength:
24
26
  - "spec/**/*.*"
25
27
  - "*.gemspec"
26
28
 
27
- Lint/HandleExceptions:
29
+ Lint/SuppressedException:
28
30
  Exclude:
29
31
  - "spec/**/*.*"
30
32
 
@@ -48,3 +50,12 @@ Style/TrailingCommaInHashLiteral:
48
50
 
49
51
  Style/StringLiterals:
50
52
  EnforcedStyle: double_quotes
53
+
54
+ Style/HashEachMethods:
55
+ Enabled: true
56
+
57
+ Style/HashTransformKeys:
58
+ Enabled: true
59
+
60
+ Style/HashTransformValues:
61
+ Enabled: true
data/Appraisals CHANGED
@@ -2,21 +2,41 @@
2
2
 
3
3
  appraise "activerecord-4-2" do
4
4
  gem "activerecord", "~> 4.2.0"
5
+ gem "sqlite3", "~> 1.3.6"
5
6
  end
6
7
 
7
8
  appraise "activerecord-5-0" do
8
9
  gem "activerecord", "~> 5.0.0"
10
+ gem "sqlite3", "~> 1.3.6"
9
11
  end
10
12
 
11
13
  appraise "activerecord-5-1" do
12
14
  gem "activerecord", "~> 5.1.0"
15
+ gem "sqlite3", "~> 1.3", ">= 1.3.6"
13
16
  end
14
17
 
15
18
  appraise "activerecord-5-2" do
16
19
  gem "activerecord", "~> 5.2.0"
20
+ gem "sqlite3", "~> 1.3", ">= 1.3.6"
21
+ end
22
+
23
+ appraise "activerecord-6-0" do
24
+ gem "activerecord", "~> 6.0.0"
25
+ gem "sqlite3", "~> 1.4"
26
+ end
27
+
28
+ appraise "activerecord-6-1" do
29
+ gem "activerecord", "~> 6.1.0"
30
+ gem "sqlite3", "~> 1.4"
31
+ gem "rspec-rails", "~> 4.0"
17
32
  end
18
33
 
19
34
  appraise "activerecord-master" do
20
- gem "rails", git: "https://github.com/rails/rails.git"
21
- gem "activerecord", git: "https://github.com/rails/rails.git"
35
+ git "https://github.com/rails/rails.git" do
36
+ gem "rails"
37
+ gem "activerecord"
38
+ end
39
+
40
+ gem "sqlite3", "~> 1.4"
41
+ gem "rspec-rails", "~> 4.0"
22
42
  end
data/CHANGELOG.md CHANGED
@@ -6,6 +6,34 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## 1.1.0 (2021-08-05)
10
+
11
+ ### Added
12
+
13
+ - Allow to call transactional callbacks directly on `AfterCommitEverywhere` module:
14
+
15
+ ```ruby
16
+ AfterCommitEverywhere.after_commit { puts "If you see me then transaction has been successfully commited!" }
17
+ ```
18
+
19
+ - Allow to call `in_transaction?` helper method from instance methods in classes that includes `AfterCommitEverywhere` module.
20
+
21
+ ## 1.0.0 (2021-02-17)
22
+
23
+ Declare gem as stable. No changes since 0.1.5.
24
+
25
+ See [#11](https://github.com/Envek/after_commit_everywhere/issues/11) for discussion.
26
+
27
+ ## 0.1.5 (2020-03-22)
28
+
29
+ ### Fixed
30
+
31
+ - [PR [#8](https://github.com/Envek/after_commit_everywhere/pull/8)] Callback registration when callback methods are aliased. ([@stokarenko])
32
+
33
+ ## 0.1.4 (2019-09-10)
34
+
35
+ - [PR [#6](https://github.com/Envek/after_commit_everywhere/pull/6)] ActiveRecord 6.0 compatibility. ([@joevandyk])
36
+
9
37
  ## 0.1.3 (2019-02-18)
10
38
 
11
39
  - Make `in_transaction?` helper method public. ([@Envek])
@@ -24,3 +52,5 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
24
52
 
25
53
  [@Envek]: https://github.com/Envek "Andrey Novikov"
26
54
  [@arjun810]: https://github.com/arjun810 "Arjun Singh"
55
+ [@joevandyk]: https://github.com/joevandyk "Joe Van Dyk"
56
+ [@stokarenko]: https://github.com/stokarenko "Sergey Tokarenko"
data/Gemfile.lock ADDED
@@ -0,0 +1,215 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ after_commit_everywhere (1.0.0)
5
+ activerecord (>= 4.2)
6
+ activesupport
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ actioncable (6.1.4)
12
+ actionpack (= 6.1.4)
13
+ activesupport (= 6.1.4)
14
+ nio4r (~> 2.0)
15
+ websocket-driver (>= 0.6.1)
16
+ actionmailbox (6.1.4)
17
+ actionpack (= 6.1.4)
18
+ activejob (= 6.1.4)
19
+ activerecord (= 6.1.4)
20
+ activestorage (= 6.1.4)
21
+ activesupport (= 6.1.4)
22
+ mail (>= 2.7.1)
23
+ actionmailer (6.1.4)
24
+ actionpack (= 6.1.4)
25
+ actionview (= 6.1.4)
26
+ activejob (= 6.1.4)
27
+ activesupport (= 6.1.4)
28
+ mail (~> 2.5, >= 2.5.4)
29
+ rails-dom-testing (~> 2.0)
30
+ actionpack (6.1.4)
31
+ actionview (= 6.1.4)
32
+ activesupport (= 6.1.4)
33
+ rack (~> 2.0, >= 2.0.9)
34
+ rack-test (>= 0.6.3)
35
+ rails-dom-testing (~> 2.0)
36
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
37
+ actiontext (6.1.4)
38
+ actionpack (= 6.1.4)
39
+ activerecord (= 6.1.4)
40
+ activestorage (= 6.1.4)
41
+ activesupport (= 6.1.4)
42
+ nokogiri (>= 1.8.5)
43
+ actionview (6.1.4)
44
+ activesupport (= 6.1.4)
45
+ builder (~> 3.1)
46
+ erubi (~> 1.4)
47
+ rails-dom-testing (~> 2.0)
48
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
49
+ active_attr (0.15.3)
50
+ actionpack (>= 3.0.2, < 7.0)
51
+ activemodel (>= 3.0.2, < 7.0)
52
+ activesupport (>= 3.0.2, < 7.0)
53
+ activejob (6.1.4)
54
+ activesupport (= 6.1.4)
55
+ globalid (>= 0.3.6)
56
+ activemodel (6.1.4)
57
+ activesupport (= 6.1.4)
58
+ activerecord (6.1.4)
59
+ activemodel (= 6.1.4)
60
+ activesupport (= 6.1.4)
61
+ activestorage (6.1.4)
62
+ actionpack (= 6.1.4)
63
+ activejob (= 6.1.4)
64
+ activerecord (= 6.1.4)
65
+ activesupport (= 6.1.4)
66
+ marcel (~> 1.0.0)
67
+ mini_mime (>= 1.1.0)
68
+ activesupport (6.1.4)
69
+ concurrent-ruby (~> 1.0, >= 1.0.2)
70
+ i18n (>= 1.6, < 2)
71
+ minitest (>= 5.1)
72
+ tzinfo (~> 2.0)
73
+ zeitwerk (~> 2.3)
74
+ anyway_config (2.1.0)
75
+ ruby-next-core (>= 0.11.0)
76
+ appraisal (2.4.1)
77
+ bundler
78
+ rake
79
+ thor (>= 0.14.0)
80
+ ast (2.4.2)
81
+ builder (3.2.4)
82
+ coderay (1.1.3)
83
+ concurrent-ruby (1.1.9)
84
+ crass (1.0.6)
85
+ diff-lcs (1.4.4)
86
+ erubi (1.10.0)
87
+ globalid (0.5.2)
88
+ activesupport (>= 5.0)
89
+ i18n (1.8.10)
90
+ concurrent-ruby (~> 1.0)
91
+ isolator (0.7.0)
92
+ sniffer (>= 0.3.1)
93
+ jaro_winkler (1.5.4)
94
+ loofah (2.11.0)
95
+ crass (~> 1.0.2)
96
+ nokogiri (>= 1.5.9)
97
+ mail (2.7.1)
98
+ mini_mime (>= 0.1.1)
99
+ marcel (1.0.1)
100
+ method_source (1.0.0)
101
+ mini_mime (1.1.0)
102
+ mini_portile2 (2.6.1)
103
+ minitest (5.14.4)
104
+ nio4r (2.5.8)
105
+ nokogiri (1.12.2)
106
+ mini_portile2 (~> 2.6.1)
107
+ racc (~> 1.4)
108
+ parallel (1.20.1)
109
+ parser (3.0.2.0)
110
+ ast (~> 2.4.1)
111
+ pry (0.14.1)
112
+ coderay (~> 1.1)
113
+ method_source (~> 1.0)
114
+ racc (1.5.2)
115
+ rack (2.2.3)
116
+ rack-test (1.1.0)
117
+ rack (>= 1.0, < 3)
118
+ rails (6.1.4)
119
+ actioncable (= 6.1.4)
120
+ actionmailbox (= 6.1.4)
121
+ actionmailer (= 6.1.4)
122
+ actionpack (= 6.1.4)
123
+ actiontext (= 6.1.4)
124
+ actionview (= 6.1.4)
125
+ activejob (= 6.1.4)
126
+ activemodel (= 6.1.4)
127
+ activerecord (= 6.1.4)
128
+ activestorage (= 6.1.4)
129
+ activesupport (= 6.1.4)
130
+ bundler (>= 1.15.0)
131
+ railties (= 6.1.4)
132
+ sprockets-rails (>= 2.0.0)
133
+ rails-dom-testing (2.0.3)
134
+ activesupport (>= 4.2.0)
135
+ nokogiri (>= 1.6)
136
+ rails-html-sanitizer (1.3.0)
137
+ loofah (~> 2.3)
138
+ railties (6.1.4)
139
+ actionpack (= 6.1.4)
140
+ activesupport (= 6.1.4)
141
+ method_source
142
+ rake (>= 0.13)
143
+ thor (~> 1.0)
144
+ rainbow (3.0.0)
145
+ rake (13.0.6)
146
+ rexml (3.2.5)
147
+ rspec (3.10.0)
148
+ rspec-core (~> 3.10.0)
149
+ rspec-expectations (~> 3.10.0)
150
+ rspec-mocks (~> 3.10.0)
151
+ rspec-core (3.10.1)
152
+ rspec-support (~> 3.10.0)
153
+ rspec-expectations (3.10.1)
154
+ diff-lcs (>= 1.2.0, < 2.0)
155
+ rspec-support (~> 3.10.0)
156
+ rspec-mocks (3.10.2)
157
+ diff-lcs (>= 1.2.0, < 2.0)
158
+ rspec-support (~> 3.10.0)
159
+ rspec-rails (5.0.1)
160
+ actionpack (>= 5.2)
161
+ activesupport (>= 5.2)
162
+ railties (>= 5.2)
163
+ rspec-core (~> 3.10)
164
+ rspec-expectations (~> 3.10)
165
+ rspec-mocks (~> 3.10)
166
+ rspec-support (~> 3.10)
167
+ rspec-support (3.10.2)
168
+ rubocop (0.81.0)
169
+ jaro_winkler (~> 1.5.1)
170
+ parallel (~> 1.10)
171
+ parser (>= 2.7.0.1)
172
+ rainbow (>= 2.2.2, < 4.0)
173
+ rexml
174
+ ruby-progressbar (~> 1.7)
175
+ unicode-display_width (>= 1.4.0, < 2.0)
176
+ ruby-next-core (0.12.0)
177
+ ruby-progressbar (1.11.0)
178
+ sniffer (0.4.0)
179
+ active_attr (>= 0.10.2)
180
+ anyway_config (>= 1.0)
181
+ sprockets (4.0.2)
182
+ concurrent-ruby (~> 1.0)
183
+ rack (> 1, < 3)
184
+ sprockets-rails (3.2.2)
185
+ actionpack (>= 4.0)
186
+ activesupport (>= 4.0)
187
+ sprockets (>= 3.0.0)
188
+ sqlite3 (1.4.2)
189
+ thor (1.1.0)
190
+ tzinfo (2.0.4)
191
+ concurrent-ruby (~> 1.0)
192
+ unicode-display_width (1.7.0)
193
+ websocket-driver (0.7.5)
194
+ websocket-extensions (>= 0.1.0)
195
+ websocket-extensions (0.1.5)
196
+ zeitwerk (2.4.2)
197
+
198
+ PLATFORMS
199
+ ruby
200
+
201
+ DEPENDENCIES
202
+ after_commit_everywhere!
203
+ appraisal
204
+ bundler (~> 2.0)
205
+ isolator (~> 0.7)
206
+ pry
207
+ rails
208
+ rake (~> 13.0)
209
+ rspec (~> 3.0)
210
+ rspec-rails
211
+ rubocop (~> 0.81.0)
212
+ sqlite3 (~> 1.3, >= 1.3.6)
213
+
214
+ BUNDLED WITH
215
+ 2.2.25
data/README.md CHANGED
@@ -1,13 +1,12 @@
1
1
  [![Gem Version](https://badge.fury.io/rb/after_commit_everywhere.svg)](https://rubygems.org/gems/after_commit_everywhere)
2
- [![Build Status](https://travis-ci.org/Envek/after_commit_everywhere.svg?branch=master)](https://travis-ci.org/Envek/after_commit_everywhere)
3
2
 
4
3
  # `after_commit` everywhere
5
4
 
6
- Allows to use ActiveRecord transactional callbacks outside of ActiveRecord models, literally everywhere in your application.
5
+ Allows to use ActiveRecord transactional callbacks **outside** of ActiveRecord models, literally everywhere in your application.
7
6
 
8
7
  Inspired by these articles:
9
8
 
10
- - https://dev.to/evilmartians/rails-aftercommit-everywhere--4j9g
9
+ - https://evilmartians.com/chronicles/rails-after_commit-everywhere
11
10
  - https://blog.arkency.com/2015/10/run-it-in-background-job-after-commit/
12
11
 
13
12
  <a href="https://evilmartians.com/?utm_source=after_commit_everywhere&utm_campaign=project_page"><img src="https://evilmartians.com/badges/sponsored-by-evil-martians.svg" alt="Sponsored by Evil Martians" width="236" height="54"></a>
@@ -56,6 +55,12 @@ ActiveRecord::Base.transaction do
56
55
  end
57
56
  ```
58
57
 
58
+ Or call it directly on module:
59
+
60
+ ```ruby
61
+ AfterCommitEverywhere.after_commit { puts "We're all done!" }
62
+ ```
63
+
59
64
  That's it!
60
65
 
61
66
  But the main benefit is that it works with nested `transaction` blocks (may be even spread across many files in your codebase):
@@ -108,18 +113,103 @@ If called outside transaction will raise an exception!
108
113
 
109
114
  Please keep in mind ActiveRecord's [limitations for rolling back nested transactions](http://api.rubyonrails.org/classes/ActiveRecord/Transactions/ClassMethods.html#module-ActiveRecord::Transactions::ClassMethods-label-Nested+transactions).
110
115
 
116
+ ### Available helper methods
117
+
118
+ #### `in_transaction?`
119
+
120
+ Returns `true` when called inside open transaction, `false` otherwise.
121
+
111
122
  ### FAQ
112
123
 
113
124
  #### Does it works with transactional_test or DatabaseCleaner
114
125
 
115
126
  **Yes**.
116
127
 
128
+ ### Be aware of mental traps
129
+
130
+ While it is convenient to have `after_commit` method at a class level to be able to call it from anywhere, take care not to call it on models.
131
+
132
+ So, **DO NOT DO THIS**:
133
+
134
+ ```ruby
135
+ class Post < ActiveRecord::Base
136
+ def self.bulk_ops
137
+ find_each do
138
+ after_commit { raise "Some doesn't expect that this screw up everything, but they should" }
139
+ end
140
+ end
141
+ end
142
+ ```
143
+
144
+ By calling [the class level `after_commit` method on models](https://api.rubyonrails.org/classes/ActiveRecord/Transactions/ClassMethods.html#method-i-after_commit), you're effectively adding callback for all `Post` instances, including **future** ones.
145
+
146
+ See https://github.com/Envek/after_commit_everywhere/issues/13 for details.
147
+
148
+ #### But what if I want to use it inside models anyway?
149
+
150
+ In class-level methods call `AfterCommitEverywhere.after_commit` directly:
151
+
152
+ ```ruby
153
+ class Post < ActiveRecord::Base
154
+ def self.bulk_ops
155
+ find_each do
156
+ AfterCommitEverywhere.after_commit { puts "Now it works as expected!" }
157
+ end
158
+ end
159
+ end
160
+ ```
161
+
162
+ For usage in instance-level methods include this module to your model class (or right into your `ApplicationRecord`):
163
+
164
+ ```ruby
165
+ class Post < ActiveRecord::Base
166
+ include AfterCommitEverywhere
167
+
168
+ def do_some_stuff
169
+ after_commit { puts "Now it works!" }
170
+ end
171
+ end
172
+ ```
173
+
174
+ However, if you do something in models that requires defining such ad-hoc transactional callbacks, it may indicate that your models have too many responsibilities and these methods should be extracted to separate secialized layers (service objects, etc).
117
175
 
118
176
  ## Development
119
177
 
120
178
  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.
121
179
 
122
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
180
+ To install this gem onto your local machine, run `bundle exec rake install`.
181
+
182
+ ### Releasing new versions
183
+
184
+ 1. Bump version number in `lib/after_commit_everywhere/version.rb`
185
+
186
+ In case of pre-releases keep in mind [rubygems/rubygems#3086](https://github.com/rubygems/rubygems/issues/3086) and check version with command like `Gem::Version.new(AfterCommitEverywhere::VERSION).to_s`
187
+
188
+ 2. Fill `CHANGELOG.md` with missing changes, add header with version and date.
189
+
190
+ 3. Make a commit:
191
+
192
+ ```sh
193
+ git add lib/after_commit_everywhere/version.rb CHANGELOG.md
194
+ version=$(ruby -r ./lib/after_commit_everywhere/version.rb -e "puts Gem::Version.new(AfterCommitEverywhere::VERSION)")
195
+ git commit --message="${version}: " --edit
196
+ ```
197
+
198
+ 4. Create annotated tag:
199
+
200
+ ```sh
201
+ git tag v${version} --annotate --message="${version}: " --edit --sign
202
+ ```
203
+
204
+ 5. Fill version name into subject line and (optionally) some description (list of changes will be taken from `CHANGELOG.md` and appended automatically)
205
+
206
+ 6. Push it:
207
+
208
+ ```sh
209
+ git push --follow-tags
210
+ ```
211
+
212
+ 7. GitHub Actions will create a new release, build and push gem into [rubygems.org](https://rubygems.org)! You're done!
123
213
 
124
214
 
125
215
  ## Contributing
@@ -29,14 +29,15 @@ Gem::Specification.new do |spec|
29
29
  spec.require_paths = ["lib"]
30
30
 
31
31
  spec.add_dependency "activerecord", ">= 4.2"
32
+ spec.add_dependency "activesupport"
32
33
  spec.add_development_dependency "appraisal"
33
- spec.add_development_dependency "bundler", "~> 1.16"
34
- spec.add_development_dependency "isolator"
34
+ spec.add_development_dependency "bundler", "~> 2.0"
35
+ spec.add_development_dependency "isolator", "~> 0.7"
35
36
  spec.add_development_dependency "pry"
36
37
  spec.add_development_dependency "rails"
37
- spec.add_development_dependency "rake", "~> 10.0"
38
+ spec.add_development_dependency "rake", "~> 13.0"
38
39
  spec.add_development_dependency "rspec", "~> 3.0"
39
40
  spec.add_development_dependency "rspec-rails"
40
- spec.add_development_dependency "rubocop", "~> 0.64"
41
- spec.add_development_dependency "sqlite3", "~> 1.3.6"
41
+ spec.add_development_dependency "rubocop", "~> 0.81.0"
42
+ spec.add_development_dependency "sqlite3", "~> 1.3", ">= 1.3.6"
42
43
  end
@@ -1,9 +1,8 @@
1
- # frozen_string_literal: true
2
-
3
1
  # This file was generated by Appraisal
4
2
 
5
3
  source "https://rubygems.org"
6
4
 
7
5
  gem "activerecord", "~> 4.2.0"
6
+ gem "sqlite3", "~> 1.3.6"
8
7
 
9
8
  gemspec path: "../"
@@ -1,9 +1,8 @@
1
- # frozen_string_literal: true
2
-
3
1
  # This file was generated by Appraisal
4
2
 
5
3
  source "https://rubygems.org"
6
4
 
7
5
  gem "activerecord", "~> 5.0.0"
6
+ gem "sqlite3", "~> 1.3.6"
8
7
 
9
8
  gemspec path: "../"
@@ -1,9 +1,8 @@
1
- # frozen_string_literal: true
2
-
3
1
  # This file was generated by Appraisal
4
2
 
5
3
  source "https://rubygems.org"
6
4
 
7
5
  gem "activerecord", "~> 5.1.0"
6
+ gem "sqlite3", "~> 1.3", ">= 1.3.6"
8
7
 
9
8
  gemspec path: "../"
@@ -1,9 +1,8 @@
1
- # frozen_string_literal: true
2
-
3
1
  # This file was generated by Appraisal
4
2
 
5
3
  source "https://rubygems.org"
6
4
 
7
5
  gem "activerecord", "~> 5.2.0"
6
+ gem "sqlite3", "~> 1.3", ">= 1.3.6"
8
7
 
9
8
  gemspec path: "../"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 6.0.0"
6
+ gem "sqlite3", "~> 1.4"
7
+
8
+ gemspec path: "../"
@@ -0,0 +1,9 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 6.1.0"
6
+ gem "sqlite3", "~> 1.4"
7
+ gem "rspec-rails", "~> 4.0"
8
+
9
+ gemspec path: "../"
@@ -1,10 +1,13 @@
1
- # frozen_string_literal: true
2
-
3
1
  # This file was generated by Appraisal
4
2
 
5
3
  source "https://rubygems.org"
6
4
 
7
- gem "activerecord", git: "https://github.com/rails/rails.git"
8
- gem "rails", git: "https://github.com/rails/rails.git"
5
+ git "https://github.com/rails/rails.git" do
6
+ gem "rails"
7
+ gem "activerecord"
8
+ end
9
+
10
+ gem "sqlite3", "~> 1.4"
11
+ gem "rspec-rails", "~> 4.0"
9
12
 
10
13
  gemspec path: "../"
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "active_record"
4
+ require "active_support/core_ext/module/delegation"
4
5
 
5
6
  require "after_commit_everywhere/version"
6
7
  require "after_commit_everywhere/wrap"
@@ -12,65 +13,69 @@ require "after_commit_everywhere/wrap"
12
13
  module AfterCommitEverywhere
13
14
  class NotInTransaction < RuntimeError; end
14
15
 
15
- # Runs +callback+ after successful commit of outermost transaction for
16
- # database +connection+.
17
- #
18
- # If called outside transaction it will execute callback immediately.
19
- #
20
- # @param connection [ActiveRecord::ConnectionAdapters::AbstractAdapter]
21
- # @param callback [#call] Callback to be executed
22
- # @return void
23
- def after_commit(connection: ActiveRecord::Base.connection, &callback)
24
- AfterCommitEverywhere.register_callback(
25
- connection: connection,
26
- name: __callee__,
27
- callback: callback,
28
- no_tx_action: :execute,
29
- )
30
- end
16
+ delegate :after_commit, :before_commit, :after_rollback, to: AfterCommitEverywhere
17
+ delegate :in_transaction?, to: AfterCommitEverywhere
31
18
 
32
- # Runs +callback+ before committing of outermost transaction for +connection+.
33
- #
34
- # If called outside transaction it will execute callback immediately.
35
- #
36
- # Available only since Ruby on Rails 5.0. See https://github.com/rails/rails/pull/18936
37
- #
38
- # @param connection [ActiveRecord::ConnectionAdapters::AbstractAdapter]
39
- # @param callback [#call] Callback to be executed
40
- # @return void
41
- def before_commit(connection: ActiveRecord::Base.connection, &callback)
42
- if ActiveRecord::VERSION::MAJOR < 5
43
- raise NotImplementedError, "#{__callee__} works only with Rails 5.0+"
19
+ class << self
20
+ # Runs +callback+ after successful commit of outermost transaction for
21
+ # database +connection+.
22
+ #
23
+ # If called outside transaction it will execute callback immediately.
24
+ #
25
+ # @param connection [ActiveRecord::ConnectionAdapters::AbstractAdapter]
26
+ # @param callback [#call] Callback to be executed
27
+ # @return void
28
+ def after_commit(connection: ActiveRecord::Base.connection, &callback)
29
+ register_callback(
30
+ connection: connection,
31
+ name: __method__,
32
+ callback: callback,
33
+ no_tx_action: :execute,
34
+ )
44
35
  end
45
36
 
46
- AfterCommitEverywhere.register_callback(
47
- connection: connection,
48
- name: __callee__,
49
- callback: callback,
50
- no_tx_action: :warn_and_execute,
51
- )
52
- end
37
+ # Runs +callback+ before committing of outermost transaction for +connection+.
38
+ #
39
+ # If called outside transaction it will execute callback immediately.
40
+ #
41
+ # Available only since Ruby on Rails 5.0. See https://github.com/rails/rails/pull/18936
42
+ #
43
+ # @param connection [ActiveRecord::ConnectionAdapters::AbstractAdapter]
44
+ # @param callback [#call] Callback to be executed
45
+ # @return void
46
+ def before_commit(connection: ActiveRecord::Base.connection, &callback)
47
+ if ActiveRecord::VERSION::MAJOR < 5
48
+ raise NotImplementedError, "#{__method__} works only with Rails 5.0+"
49
+ end
53
50
 
54
- # Runs +callback+ after rolling back of transaction or savepoint (if declared
55
- # in nested transaction) for database +connection+.
56
- #
57
- # Caveat: do not raise +ActivRecord::Rollback+ in nested transaction block!
58
- # See http://api.rubyonrails.org/classes/ActiveRecord/Transactions/ClassMethods.html#module-ActiveRecord::Transactions::ClassMethods-label-Nested+transactions
59
- #
60
- # @param connection [ActiveRecord::ConnectionAdapters::AbstractAdapter]
61
- # @param callback [#call] Callback to be executed
62
- # @return void
63
- # @raise [NotInTransaction] if called outside transaction.
64
- def after_rollback(connection: ActiveRecord::Base.connection, &callback)
65
- AfterCommitEverywhere.register_callback(
66
- connection: connection,
67
- name: __callee__,
68
- callback: callback,
69
- no_tx_action: :exception,
70
- )
71
- end
51
+ register_callback(
52
+ connection: connection,
53
+ name: __method__,
54
+ callback: callback,
55
+ no_tx_action: :warn_and_execute,
56
+ )
57
+ end
72
58
 
73
- class << self
59
+ # Runs +callback+ after rolling back of transaction or savepoint (if declared
60
+ # in nested transaction) for database +connection+.
61
+ #
62
+ # Caveat: do not raise +ActivRecord::Rollback+ in nested transaction block!
63
+ # See http://api.rubyonrails.org/classes/ActiveRecord/Transactions/ClassMethods.html#module-ActiveRecord::Transactions::ClassMethods-label-Nested+transactions
64
+ #
65
+ # @param connection [ActiveRecord::ConnectionAdapters::AbstractAdapter]
66
+ # @param callback [#call] Callback to be executed
67
+ # @return void
68
+ # @raise [NotInTransaction] if called outside transaction.
69
+ def after_rollback(connection: ActiveRecord::Base.connection, &callback)
70
+ register_callback(
71
+ connection: connection,
72
+ name: __method__,
73
+ callback: callback,
74
+ no_tx_action: :exception,
75
+ )
76
+ end
77
+
78
+ # @api private
74
79
  def register_callback(connection:, name:, no_tx_action:, callback:)
75
80
  raise ArgumentError, "Provide callback to #{name}" unless callback
76
81
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AfterCommitEverywhere
4
- VERSION = "0.1.3"
4
+ VERSION = "1.1.0"
5
5
  end
@@ -19,6 +19,10 @@ module AfterCommitEverywhere
19
19
  @handlers[:before_commit]&.call
20
20
  end
21
21
 
22
+ def trigger_transactional_callbacks?
23
+ true
24
+ end
25
+
22
26
  def committed!(*)
23
27
  @handlers[:after_commit]&.call
24
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: after_commit_everywhere
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrey Novikov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-02-18 00:00:00.000000000 Z
11
+ date: 2021-08-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '4.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
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: appraisal
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -44,28 +58,28 @@ dependencies:
44
58
  requirements:
45
59
  - - "~>"
46
60
  - !ruby/object:Gem::Version
47
- version: '1.16'
61
+ version: '2.0'
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
66
  - - "~>"
53
67
  - !ruby/object:Gem::Version
54
- version: '1.16'
68
+ version: '2.0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: isolator
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
- - - ">="
73
+ - - "~>"
60
74
  - !ruby/object:Gem::Version
61
- version: '0'
75
+ version: '0.7'
62
76
  type: :development
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
- - - ">="
80
+ - - "~>"
67
81
  - !ruby/object:Gem::Version
68
- version: '0'
82
+ version: '0.7'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: pry
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -100,14 +114,14 @@ dependencies:
100
114
  requirements:
101
115
  - - "~>"
102
116
  - !ruby/object:Gem::Version
103
- version: '10.0'
117
+ version: '13.0'
104
118
  type: :development
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
107
121
  requirements:
108
122
  - - "~>"
109
123
  - !ruby/object:Gem::Version
110
- version: '10.0'
124
+ version: '13.0'
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: rspec
113
127
  requirement: !ruby/object:Gem::Requirement
@@ -142,19 +156,22 @@ dependencies:
142
156
  requirements:
143
157
  - - "~>"
144
158
  - !ruby/object:Gem::Version
145
- version: '0.64'
159
+ version: 0.81.0
146
160
  type: :development
147
161
  prerelease: false
148
162
  version_requirements: !ruby/object:Gem::Requirement
149
163
  requirements:
150
164
  - - "~>"
151
165
  - !ruby/object:Gem::Version
152
- version: '0.64'
166
+ version: 0.81.0
153
167
  - !ruby/object:Gem::Dependency
154
168
  name: sqlite3
155
169
  requirement: !ruby/object:Gem::Requirement
156
170
  requirements:
157
171
  - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: '1.3'
174
+ - - ">="
158
175
  - !ruby/object:Gem::Version
159
176
  version: 1.3.6
160
177
  type: :development
@@ -162,6 +179,9 @@ dependencies:
162
179
  version_requirements: !ruby/object:Gem::Requirement
163
180
  requirements:
164
181
  - - "~>"
182
+ - !ruby/object:Gem::Version
183
+ version: '1.3'
184
+ - - ">="
165
185
  - !ruby/object:Gem::Version
166
186
  version: 1.3.6
167
187
  description: Brings before_commit, after_commit, and after_rollback transactional
@@ -172,13 +192,15 @@ executables: []
172
192
  extensions: []
173
193
  extra_rdoc_files: []
174
194
  files:
195
+ - ".github/workflows/release.yml"
196
+ - ".github/workflows/test.yml"
175
197
  - ".gitignore"
176
198
  - ".rspec"
177
199
  - ".rubocop.yml"
178
- - ".travis.yml"
179
200
  - Appraisals
180
201
  - CHANGELOG.md
181
202
  - Gemfile
203
+ - Gemfile.lock
182
204
  - LICENSE.txt
183
205
  - README.md
184
206
  - Rakefile
@@ -190,6 +212,8 @@ files:
190
212
  - gemfiles/activerecord_5_0.gemfile
191
213
  - gemfiles/activerecord_5_1.gemfile
192
214
  - gemfiles/activerecord_5_2.gemfile
215
+ - gemfiles/activerecord_6_0.gemfile
216
+ - gemfiles/activerecord_6_1.gemfile
193
217
  - gemfiles/activerecord_master.gemfile
194
218
  - lib/after_commit_everywhere.rb
195
219
  - lib/after_commit_everywhere/version.rb
@@ -214,7 +238,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
214
238
  - !ruby/object:Gem::Version
215
239
  version: '0'
216
240
  requirements: []
217
- rubygems_version: 3.0.1
241
+ rubygems_version: 3.1.6
218
242
  signing_key:
219
243
  specification_version: 4
220
244
  summary: Executes code after database commit wherever you want in your application
data/.travis.yml DELETED
@@ -1,34 +0,0 @@
1
- cache: bundler
2
- sudo: false
3
- language: ruby
4
-
5
- addons:
6
- apt:
7
- sources:
8
- - travis-ci/sqlite3
9
- packages:
10
- - sqlite3
11
-
12
- matrix:
13
- include:
14
- - rvm: 2.5.3
15
- gemfile: gemfiles/activerecord_4_2.gemfile
16
- - rvm: 2.5.3
17
- gemfile: gemfiles/activerecord_5_0.gemfile
18
- - rvm: 2.5.3
19
- gemfile: gemfiles/activerecord_5_1.gemfile
20
- - rvm: 2.4.5
21
- gemfile: gemfiles/activerecord_5_2.gemfile
22
- - rvm: 2.3.8
23
- gemfile: gemfiles/activerecord_5_2.gemfile
24
- - rvm: 2.5.3
25
- gemfile: gemfiles/activerecord_5_2.gemfile
26
- - rvm: 2.6.1
27
- gemfile: gemfiles/activerecord_5_2.gemfile
28
- - rvm: 2.6.1
29
- gemfile: gemfiles/activerecord_master.gemfile
30
-
31
- # https://github.com/travis-ci/travis-ci/issues/8969#issuecomment-380028168
32
- before_install:
33
- - gem update --system
34
- - gem install bundler -v "~> 1.17.2"