after_commit_everywhere 0.1.5 → 1.2.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: 6f7dffbee6c4b998b64035990acfa7f7ccd7dcfc835f381ca89b91a5f029b492
4
- data.tar.gz: fb2e0b10ac621c60ae287eabaf7d22535c99aa050f8bd9d46c49a1fbeb72b259
3
+ metadata.gz: 22ac14ea80692909c9a464d9ad47d3c8d29950e020530a435e1def88763fd53f
4
+ data.tar.gz: 761b7db7496e62837332714f55b9f9f916fd5b4d515515d18bab7947cb226270
5
5
  SHA512:
6
- metadata.gz: 893f9cbc92941e7b74bf10f2b4069f117dd75dbc3c8dcfdaffb617d1effcd65cbd770a9787de81ef8b3bab885b673f7d706eddad559c3333305525a58413010b
7
- data.tar.gz: 3c99ffe5725cfe99ce564af504a70614a97f8ba1007b73ae3b130ff49ece0d9fc323ebdbb34369def92e42fed8c0b9a1467362e029d23207716edef1c3907ccf
6
+ metadata.gz: 4d764c065a1d7fd99614e0e98c270a211a5a6fcb661068cb3edfaf34910d58b2a9754838fd6e5bf06f27e2caf6bb23209d8508153388de350250a52e26a466d9
7
+ data.tar.gz: 20e3d66fdd8ecf32ac6087fe2d5142676577445c254bf750845d430ada830f5b7b121d35a76e486cd71468b11c67ce7f42ba721bf46db7f0370c13db0d177072
@@ -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,57 @@
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.6'
22
+ activerecord: '5.2'
23
+ gemfile: 'activerecord_5_2.gemfile'
24
+ - ruby: '2.7'
25
+ activerecord: '6.0'
26
+ gemfile: 'activerecord_6_0.gemfile'
27
+ - ruby: '2.7'
28
+ activerecord: '6.1'
29
+ gemfile: 'activerecord_6_1.gemfile'
30
+ - ruby: '3.0'
31
+ activerecord: '7.0'
32
+ gemfile: 'activerecord_7_0.gemfile'
33
+ - ruby: '3.1'
34
+ activerecord: 'HEAD'
35
+ gemfile: 'activerecord_master.gemfile'
36
+ container:
37
+ image: ruby:${{ matrix.ruby }}
38
+ env:
39
+ CI: true
40
+ BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}
41
+ steps:
42
+ - uses: actions/checkout@v2
43
+ - uses: actions/cache@v2
44
+ with:
45
+ path: vendor/bundle
46
+ key: bundle-${{ matrix.ruby }}-${{ hashFiles('**/*.gemspec') }}-${{ hashFiles('**/Gemfile') }}
47
+ restore-keys: |
48
+ bundle-${{ matrix.ruby }}-${{ hashFiles('**/*.gemspec') }}-${{ hashFiles('**/Gemfile') }}
49
+ bundle-${{ matrix.ruby }}-
50
+ - name: Upgrade Bundler to 2.x (mostly for Rubies older than 2.7)
51
+ run: gem install bundler -v '~> 2.0' -v '!= 2.2.10'
52
+ - name: Bundle install
53
+ run: |
54
+ bundle config path vendor/bundle
55
+ bundle update
56
+ - name: Run RSpec
57
+ run: bundle exec rspec
data/Appraisals CHANGED
@@ -25,9 +25,24 @@ appraise "activerecord-6-0" do
25
25
  gem "sqlite3", "~> 1.4"
26
26
  end
27
27
 
28
+ appraise "activerecord-6-1" do
29
+ gem "activerecord", "~> 6.1.0"
30
+ gem "sqlite3", "~> 1.4"
31
+ gem "rspec-rails", "~> 4.0"
32
+ end
33
+
34
+ appraise "activerecord-7-0" do
35
+ gem "activerecord", "~> 7.0.0"
36
+ gem "sqlite3", "~> 1.4"
37
+ gem "rspec-rails", "~> 5.0"
38
+ end
39
+
28
40
  appraise "activerecord-master" do
29
- gem "rails", git: "https://github.com/rails/rails.git"
30
- gem "activerecord", git: "https://github.com/rails/rails.git"
41
+ git "https://github.com/rails/rails.git" do
42
+ gem "rails"
43
+ gem "activerecord"
44
+ end
45
+
31
46
  gem "sqlite3", "~> 1.4"
32
- gem "rspec-rails", "~> 4.0.0.rc1"
47
+ gem "rspec-rails", "~> 5.0"
33
48
  end
data/CHANGELOG.md CHANGED
@@ -4,7 +4,43 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5
5
  and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6
6
 
7
- ## [Unreleased]
7
+ ## 1.2.0 (2022-03-26)
8
+
9
+ ### Added
10
+
11
+ - Allow to change callbacks' behavior when they are called outside transaction:
12
+
13
+ ```ruby
14
+ AfterCommitEverywhere.after_commit(without_tx: :raise) do
15
+ # Will be executed only if was called within transaction
16
+ # Error will be raised otherwise
17
+ end
18
+ ```
19
+
20
+ Available values for `without_tx` keyword argument:
21
+ - `:execute` to execute callback immediately
22
+ - `:warn_and_execute` to print warning and execute immediately
23
+ - `:raise` to raise an exception instead of executing
24
+
25
+ [Pull request #18](https://github.com/Envek/after_commit_everywhere/pull/18) by [@lolripgg][].
26
+
27
+ ## 1.1.0 (2021-08-05)
28
+
29
+ ### Added
30
+
31
+ - Allow to call transactional callbacks directly on `AfterCommitEverywhere` module:
32
+
33
+ ```ruby
34
+ AfterCommitEverywhere.after_commit { puts "If you see me then transaction has been successfully commited!" }
35
+ ```
36
+
37
+ - Allow to call `in_transaction?` helper method from instance methods in classes that includes `AfterCommitEverywhere` module.
38
+
39
+ ## 1.0.0 (2021-02-17)
40
+
41
+ Declare gem as stable. No changes since 0.1.5.
42
+
43
+ See [#11](https://github.com/Envek/after_commit_everywhere/issues/11) for discussion.
8
44
 
9
45
  ## 0.1.5 (2020-03-22)
10
46
 
@@ -36,3 +72,4 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
36
72
  [@arjun810]: https://github.com/arjun810 "Arjun Singh"
37
73
  [@joevandyk]: https://github.com/joevandyk "Joe Van Dyk"
38
74
  [@stokarenko]: https://github.com/stokarenko "Sergey Tokarenko"
75
+ [@lolripgg]: https://github.com/lolripgg "James Brewer"
data/Gemfile.lock CHANGED
@@ -1,193 +1,217 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- after_commit_everywhere (0.1.4)
4
+ after_commit_everywhere (1.1.0)
5
5
  activerecord (>= 4.2)
6
+ activesupport
6
7
 
7
8
  GEM
8
9
  remote: https://rubygems.org/
9
10
  specs:
10
- actioncable (6.0.2.2)
11
- actionpack (= 6.0.2.2)
11
+ actioncable (7.0.2.3)
12
+ actionpack (= 7.0.2.3)
13
+ activesupport (= 7.0.2.3)
12
14
  nio4r (~> 2.0)
13
15
  websocket-driver (>= 0.6.1)
14
- actionmailbox (6.0.2.2)
15
- actionpack (= 6.0.2.2)
16
- activejob (= 6.0.2.2)
17
- activerecord (= 6.0.2.2)
18
- activestorage (= 6.0.2.2)
19
- activesupport (= 6.0.2.2)
16
+ actionmailbox (7.0.2.3)
17
+ actionpack (= 7.0.2.3)
18
+ activejob (= 7.0.2.3)
19
+ activerecord (= 7.0.2.3)
20
+ activestorage (= 7.0.2.3)
21
+ activesupport (= 7.0.2.3)
20
22
  mail (>= 2.7.1)
21
- actionmailer (6.0.2.2)
22
- actionpack (= 6.0.2.2)
23
- actionview (= 6.0.2.2)
24
- activejob (= 6.0.2.2)
23
+ net-imap
24
+ net-pop
25
+ net-smtp
26
+ actionmailer (7.0.2.3)
27
+ actionpack (= 7.0.2.3)
28
+ actionview (= 7.0.2.3)
29
+ activejob (= 7.0.2.3)
30
+ activesupport (= 7.0.2.3)
25
31
  mail (~> 2.5, >= 2.5.4)
32
+ net-imap
33
+ net-pop
34
+ net-smtp
26
35
  rails-dom-testing (~> 2.0)
27
- actionpack (6.0.2.2)
28
- actionview (= 6.0.2.2)
29
- activesupport (= 6.0.2.2)
30
- rack (~> 2.0, >= 2.0.8)
36
+ actionpack (7.0.2.3)
37
+ actionview (= 7.0.2.3)
38
+ activesupport (= 7.0.2.3)
39
+ rack (~> 2.0, >= 2.2.0)
31
40
  rack-test (>= 0.6.3)
32
41
  rails-dom-testing (~> 2.0)
33
42
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
34
- actiontext (6.0.2.2)
35
- actionpack (= 6.0.2.2)
36
- activerecord (= 6.0.2.2)
37
- activestorage (= 6.0.2.2)
38
- activesupport (= 6.0.2.2)
43
+ actiontext (7.0.2.3)
44
+ actionpack (= 7.0.2.3)
45
+ activerecord (= 7.0.2.3)
46
+ activestorage (= 7.0.2.3)
47
+ activesupport (= 7.0.2.3)
48
+ globalid (>= 0.6.0)
39
49
  nokogiri (>= 1.8.5)
40
- actionview (6.0.2.2)
41
- activesupport (= 6.0.2.2)
50
+ actionview (7.0.2.3)
51
+ activesupport (= 7.0.2.3)
42
52
  builder (~> 3.1)
43
53
  erubi (~> 1.4)
44
54
  rails-dom-testing (~> 2.0)
45
55
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
46
- active_attr (0.15.0)
47
- actionpack (>= 3.0.2, < 6.1)
48
- activemodel (>= 3.0.2, < 6.1)
49
- activesupport (>= 3.0.2, < 6.1)
50
- activejob (6.0.2.2)
51
- activesupport (= 6.0.2.2)
56
+ active_attr (0.15.4)
57
+ actionpack (>= 3.0.2, < 7.1)
58
+ activemodel (>= 3.0.2, < 7.1)
59
+ activesupport (>= 3.0.2, < 7.1)
60
+ activejob (7.0.2.3)
61
+ activesupport (= 7.0.2.3)
52
62
  globalid (>= 0.3.6)
53
- activemodel (6.0.2.2)
54
- activesupport (= 6.0.2.2)
55
- activerecord (6.0.2.2)
56
- activemodel (= 6.0.2.2)
57
- activesupport (= 6.0.2.2)
58
- activestorage (6.0.2.2)
59
- actionpack (= 6.0.2.2)
60
- activejob (= 6.0.2.2)
61
- activerecord (= 6.0.2.2)
62
- marcel (~> 0.3.1)
63
- activesupport (6.0.2.2)
63
+ activemodel (7.0.2.3)
64
+ activesupport (= 7.0.2.3)
65
+ activerecord (7.0.2.3)
66
+ activemodel (= 7.0.2.3)
67
+ activesupport (= 7.0.2.3)
68
+ activestorage (7.0.2.3)
69
+ actionpack (= 7.0.2.3)
70
+ activejob (= 7.0.2.3)
71
+ activerecord (= 7.0.2.3)
72
+ activesupport (= 7.0.2.3)
73
+ marcel (~> 1.0)
74
+ mini_mime (>= 1.1.0)
75
+ activesupport (7.0.2.3)
64
76
  concurrent-ruby (~> 1.0, >= 1.0.2)
65
- i18n (>= 0.7, < 2)
66
- minitest (~> 5.1)
67
- tzinfo (~> 1.1)
68
- zeitwerk (~> 2.2)
69
- anyway_config (1.4.4)
70
- appraisal (2.2.0)
77
+ i18n (>= 1.6, < 2)
78
+ minitest (>= 5.1)
79
+ tzinfo (~> 2.0)
80
+ anyway_config (2.3.0)
81
+ ruby-next-core (>= 0.14.0)
82
+ appraisal (2.4.1)
71
83
  bundler
72
84
  rake
73
85
  thor (>= 0.14.0)
74
- ast (2.4.0)
86
+ ast (2.4.2)
75
87
  builder (3.2.4)
76
- coderay (1.1.2)
77
- concurrent-ruby (1.1.6)
88
+ coderay (1.1.3)
89
+ concurrent-ruby (1.1.10)
78
90
  crass (1.0.6)
79
- diff-lcs (1.3)
80
- erubi (1.9.0)
81
- globalid (0.4.2)
82
- activesupport (>= 4.2.0)
83
- i18n (1.8.2)
91
+ diff-lcs (1.5.0)
92
+ digest (3.1.0)
93
+ erubi (1.10.0)
94
+ globalid (1.0.0)
95
+ activesupport (>= 5.0)
96
+ i18n (1.10.0)
84
97
  concurrent-ruby (~> 1.0)
85
- isolator (0.6.2)
98
+ io-wait (0.2.1)
99
+ isolator (0.8.0)
86
100
  sniffer (>= 0.3.1)
87
101
  jaro_winkler (1.5.4)
88
- loofah (2.4.0)
102
+ loofah (2.15.0)
89
103
  crass (~> 1.0.2)
90
104
  nokogiri (>= 1.5.9)
91
105
  mail (2.7.1)
92
106
  mini_mime (>= 0.1.1)
93
- marcel (0.3.3)
94
- mimemagic (~> 0.3.2)
107
+ marcel (1.0.2)
95
108
  method_source (1.0.0)
96
- mimemagic (0.3.4)
97
- mini_mime (1.0.2)
98
- mini_portile2 (2.4.0)
99
- minitest (5.14.0)
100
- nio4r (2.5.2)
101
- nokogiri (1.10.9)
102
- mini_portile2 (~> 2.4.0)
103
- parallel (1.19.1)
104
- parser (2.7.0.5)
105
- ast (~> 2.4.0)
106
- pry (0.13.0)
109
+ mini_mime (1.1.2)
110
+ mini_portile2 (2.8.0)
111
+ minitest (5.15.0)
112
+ net-imap (0.2.3)
113
+ digest
114
+ net-protocol
115
+ strscan
116
+ net-pop (0.1.1)
117
+ digest
118
+ net-protocol
119
+ timeout
120
+ net-protocol (0.1.2)
121
+ io-wait
122
+ timeout
123
+ net-smtp (0.3.1)
124
+ digest
125
+ net-protocol
126
+ timeout
127
+ nio4r (2.5.8)
128
+ nokogiri (1.13.3)
129
+ mini_portile2 (~> 2.8.0)
130
+ racc (~> 1.4)
131
+ parallel (1.22.1)
132
+ parser (3.1.1.0)
133
+ ast (~> 2.4.1)
134
+ pry (0.14.1)
107
135
  coderay (~> 1.1)
108
136
  method_source (~> 1.0)
109
- rack (2.2.2)
137
+ racc (1.6.0)
138
+ rack (2.2.3)
110
139
  rack-test (1.1.0)
111
140
  rack (>= 1.0, < 3)
112
- rails (6.0.2.2)
113
- actioncable (= 6.0.2.2)
114
- actionmailbox (= 6.0.2.2)
115
- actionmailer (= 6.0.2.2)
116
- actionpack (= 6.0.2.2)
117
- actiontext (= 6.0.2.2)
118
- actionview (= 6.0.2.2)
119
- activejob (= 6.0.2.2)
120
- activemodel (= 6.0.2.2)
121
- activerecord (= 6.0.2.2)
122
- activestorage (= 6.0.2.2)
123
- activesupport (= 6.0.2.2)
124
- bundler (>= 1.3.0)
125
- railties (= 6.0.2.2)
126
- sprockets-rails (>= 2.0.0)
141
+ rails (7.0.2.3)
142
+ actioncable (= 7.0.2.3)
143
+ actionmailbox (= 7.0.2.3)
144
+ actionmailer (= 7.0.2.3)
145
+ actionpack (= 7.0.2.3)
146
+ actiontext (= 7.0.2.3)
147
+ actionview (= 7.0.2.3)
148
+ activejob (= 7.0.2.3)
149
+ activemodel (= 7.0.2.3)
150
+ activerecord (= 7.0.2.3)
151
+ activestorage (= 7.0.2.3)
152
+ activesupport (= 7.0.2.3)
153
+ bundler (>= 1.15.0)
154
+ railties (= 7.0.2.3)
127
155
  rails-dom-testing (2.0.3)
128
156
  activesupport (>= 4.2.0)
129
157
  nokogiri (>= 1.6)
130
- rails-html-sanitizer (1.3.0)
158
+ rails-html-sanitizer (1.4.2)
131
159
  loofah (~> 2.3)
132
- railties (6.0.2.2)
133
- actionpack (= 6.0.2.2)
134
- activesupport (= 6.0.2.2)
160
+ railties (7.0.2.3)
161
+ actionpack (= 7.0.2.3)
162
+ activesupport (= 7.0.2.3)
135
163
  method_source
136
- rake (>= 0.8.7)
137
- thor (>= 0.20.3, < 2.0)
138
- rainbow (3.0.0)
139
- rake (13.0.1)
140
- rexml (3.2.4)
141
- rspec (3.9.0)
142
- rspec-core (~> 3.9.0)
143
- rspec-expectations (~> 3.9.0)
144
- rspec-mocks (~> 3.9.0)
145
- rspec-core (3.9.1)
146
- rspec-support (~> 3.9.1)
147
- rspec-expectations (3.9.1)
164
+ rake (>= 12.2)
165
+ thor (~> 1.0)
166
+ zeitwerk (~> 2.5)
167
+ rainbow (3.1.1)
168
+ rake (13.0.6)
169
+ rexml (3.2.5)
170
+ rspec (3.11.0)
171
+ rspec-core (~> 3.11.0)
172
+ rspec-expectations (~> 3.11.0)
173
+ rspec-mocks (~> 3.11.0)
174
+ rspec-core (3.11.0)
175
+ rspec-support (~> 3.11.0)
176
+ rspec-expectations (3.11.0)
148
177
  diff-lcs (>= 1.2.0, < 2.0)
149
- rspec-support (~> 3.9.0)
150
- rspec-mocks (3.9.1)
178
+ rspec-support (~> 3.11.0)
179
+ rspec-mocks (3.11.0)
151
180
  diff-lcs (>= 1.2.0, < 2.0)
152
- rspec-support (~> 3.9.0)
153
- rspec-rails (3.9.1)
154
- actionpack (>= 3.0)
155
- activesupport (>= 3.0)
156
- railties (>= 3.0)
157
- rspec-core (~> 3.9.0)
158
- rspec-expectations (~> 3.9.0)
159
- rspec-mocks (~> 3.9.0)
160
- rspec-support (~> 3.9.0)
161
- rspec-support (3.9.2)
162
- rubocop (0.80.1)
181
+ rspec-support (~> 3.11.0)
182
+ rspec-rails (5.1.1)
183
+ actionpack (>= 5.2)
184
+ activesupport (>= 5.2)
185
+ railties (>= 5.2)
186
+ rspec-core (~> 3.10)
187
+ rspec-expectations (~> 3.10)
188
+ rspec-mocks (~> 3.10)
189
+ rspec-support (~> 3.10)
190
+ rspec-support (3.11.0)
191
+ rubocop (0.81.0)
163
192
  jaro_winkler (~> 1.5.1)
164
193
  parallel (~> 1.10)
165
194
  parser (>= 2.7.0.1)
166
195
  rainbow (>= 2.2.2, < 4.0)
167
196
  rexml
168
197
  ruby-progressbar (~> 1.7)
169
- unicode-display_width (>= 1.4.0, < 1.7)
170
- ruby-progressbar (1.10.1)
198
+ unicode-display_width (>= 1.4.0, < 2.0)
199
+ ruby-next-core (0.15.0)
200
+ ruby-progressbar (1.11.0)
171
201
  sniffer (0.4.0)
172
202
  active_attr (>= 0.10.2)
173
203
  anyway_config (>= 1.0)
174
- sprockets (4.0.0)
175
- concurrent-ruby (~> 1.0)
176
- rack (> 1, < 3)
177
- sprockets-rails (3.2.1)
178
- actionpack (>= 4.0)
179
- activesupport (>= 4.0)
180
- sprockets (>= 3.0.0)
181
204
  sqlite3 (1.4.2)
182
- thor (1.0.1)
183
- thread_safe (0.3.6)
184
- tzinfo (1.2.6)
185
- thread_safe (~> 0.1)
186
- unicode-display_width (1.6.1)
187
- websocket-driver (0.7.1)
205
+ strscan (3.0.1)
206
+ thor (1.2.1)
207
+ timeout (0.2.0)
208
+ tzinfo (2.0.4)
209
+ concurrent-ruby (~> 1.0)
210
+ unicode-display_width (1.8.0)
211
+ websocket-driver (0.7.5)
188
212
  websocket-extensions (>= 0.1.0)
189
- websocket-extensions (0.1.4)
190
- zeitwerk (2.3.0)
213
+ websocket-extensions (0.1.5)
214
+ zeitwerk (2.5.4)
191
215
 
192
216
  PLATFORMS
193
217
  ruby
@@ -196,14 +220,14 @@ DEPENDENCIES
196
220
  after_commit_everywhere!
197
221
  appraisal
198
222
  bundler (~> 2.0)
199
- isolator
223
+ isolator (~> 0.7)
200
224
  pry
201
225
  rails
202
226
  rake (~> 13.0)
203
227
  rspec (~> 3.0)
204
228
  rspec-rails
205
- rubocop (~> 0.80)
229
+ rubocop (~> 0.81.0)
206
230
  sqlite3 (~> 1.3, >= 1.3.6)
207
231
 
208
232
  BUNDLED WITH
209
- 2.1.4
233
+ 2.2.25
data/README.md CHANGED
@@ -1,9 +1,8 @@
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
 
@@ -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,112 @@ 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
+
122
+ ### Available callback options
123
+
124
+ - `without_tx` allows to change default callback behavior if called without transaction open.
125
+
126
+ Available values:
127
+ - `:execute` to execute callback immediately
128
+ - `:warn_and_execute` to print warning and execute immediately
129
+ - `:raise` to raise an exception instead of executing
130
+
111
131
  ### FAQ
112
132
 
113
133
  #### Does it works with transactional_test or DatabaseCleaner
114
134
 
115
135
  **Yes**.
116
136
 
137
+ ### Be aware of mental traps
138
+
139
+ 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.
140
+
141
+ So, **DO NOT DO THIS**:
142
+
143
+ ```ruby
144
+ class Post < ActiveRecord::Base
145
+ def self.bulk_ops
146
+ find_each do
147
+ after_commit { raise "Some doesn't expect that this screw up everything, but they should" }
148
+ end
149
+ end
150
+ end
151
+ ```
152
+
153
+ 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.
154
+
155
+ See https://github.com/Envek/after_commit_everywhere/issues/13 for details.
156
+
157
+ #### But what if I want to use it inside models anyway?
158
+
159
+ In class-level methods call `AfterCommitEverywhere.after_commit` directly:
160
+
161
+ ```ruby
162
+ class Post < ActiveRecord::Base
163
+ def self.bulk_ops
164
+ find_each do
165
+ AfterCommitEverywhere.after_commit { puts "Now it works as expected!" }
166
+ end
167
+ end
168
+ end
169
+ ```
170
+
171
+ For usage in instance-level methods include this module to your model class (or right into your `ApplicationRecord`):
172
+
173
+ ```ruby
174
+ class Post < ActiveRecord::Base
175
+ include AfterCommitEverywhere
176
+
177
+ def do_some_stuff
178
+ after_commit { puts "Now it works!" }
179
+ end
180
+ end
181
+ ```
182
+
183
+ 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 specialized layers (service objects, etc).
117
184
 
118
185
  ## Development
119
186
 
120
187
  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
188
 
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).
189
+ To install this gem onto your local machine, run `bundle exec rake install`.
190
+
191
+ ### Releasing new versions
192
+
193
+ 1. Bump version number in `lib/after_commit_everywhere/version.rb`
194
+
195
+ 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`
196
+
197
+ 2. Fill `CHANGELOG.md` with missing changes, add header with version and date.
198
+
199
+ 3. Make a commit:
200
+
201
+ ```sh
202
+ git add lib/after_commit_everywhere/version.rb CHANGELOG.md
203
+ version=$(ruby -r ./lib/after_commit_everywhere/version.rb -e "puts Gem::Version.new(AfterCommitEverywhere::VERSION)")
204
+ git commit --message="${version}: " --edit
205
+ ```
206
+
207
+ 4. Create annotated tag:
208
+
209
+ ```sh
210
+ git tag v${version} --annotate --message="${version}: " --edit --sign
211
+ ```
212
+
213
+ 5. Fill version name into subject line and (optionally) some description (list of changes will be taken from `CHANGELOG.md` and appended automatically)
214
+
215
+ 6. Push it:
216
+
217
+ ```sh
218
+ git push --follow-tags
219
+ ```
220
+
221
+ 7. GitHub Actions will create a new release, build and push gem into [rubygems.org](https://rubygems.org)! You're done!
123
222
 
124
223
 
125
224
  ## 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
34
  spec.add_development_dependency "bundler", "~> 2.0"
34
- spec.add_development_dependency "isolator"
35
+ spec.add_development_dependency "isolator", "~> 0.7"
35
36
  spec.add_development_dependency "pry"
36
37
  spec.add_development_dependency "rails"
37
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.80"
41
+ spec.add_development_dependency "rubocop", "~> 0.81.0"
41
42
  spec.add_development_dependency "sqlite3", "~> 1.3", ">= 1.3.6"
42
43
  end
@@ -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: "../"
@@ -0,0 +1,9 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 7.0.0"
6
+ gem "sqlite3", "~> 1.4"
7
+ gem "rspec-rails", "~> 5.0"
8
+
9
+ gemspec path: "../"
@@ -2,9 +2,12 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "rails", git: "https://github.com/rails/rails.git"
6
- gem "activerecord", 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
+
7
10
  gem "sqlite3", "~> 1.4"
8
- gem "rspec-rails", "~> 4.0.0.rc1"
11
+ gem "rspec-rails", "~> 5.0"
9
12
 
10
13
  gemspec path: "../"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AfterCommitEverywhere
4
- VERSION = "0.1.5"
4
+ VERSION = "1.2.0"
5
5
  end
@@ -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,77 +13,107 @@ 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: __method__,
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, "#{__method__} works only with Rails 5.0+"
44
- end
19
+ # Causes {before_commit} and {after_commit} to raise an exception when
20
+ # called outside a transaction.
21
+ RAISE = :raise
22
+ # Causes {before_commit} and {after_commit} to execute the given callback
23
+ # immediately when called outside a transaction.
24
+ EXECUTE = :execute
25
+ # Causes {before_commit} and {after_commit} to log a warning before calling
26
+ # the given callback immediately when called outside a transaction.
27
+ WARN_AND_EXECUTE = :warn_and_execute
45
28
 
46
- AfterCommitEverywhere.register_callback(
47
- connection: connection,
48
- name: __method__,
49
- callback: callback,
50
- no_tx_action: :warn_and_execute,
29
+ class << self
30
+ # Runs +callback+ after successful commit of outermost transaction for
31
+ # database +connection+.
32
+ #
33
+ # @param connection [ActiveRecord::ConnectionAdapters::AbstractAdapter]
34
+ # @param without_tx [Symbol] Determines the behavior of this function when
35
+ # called without an open transaction.
36
+ #
37
+ # Must be one of: {RAISE}, {EXECUTE}, or {WARN_AND_EXECUTE}.
38
+ #
39
+ # @param callback [#call] Callback to be executed
40
+ # @return void
41
+ def after_commit(
42
+ connection: ActiveRecord::Base.connection,
43
+ without_tx: EXECUTE,
44
+ &callback
51
45
  )
52
- end
46
+ register_callback(
47
+ connection: connection,
48
+ name: __method__,
49
+ callback: callback,
50
+ without_tx: without_tx,
51
+ )
52
+ end
53
53
 
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: __method__,
68
- callback: callback,
69
- no_tx_action: :exception,
54
+ # Runs +callback+ before committing of outermost transaction for +connection+.
55
+ #
56
+ # Available only since Ruby on Rails 5.0. See https://github.com/rails/rails/pull/18936
57
+ #
58
+ # @param connection [ActiveRecord::ConnectionAdapters::AbstractAdapter]
59
+ # @param without_tx [Symbol] Determines the behavior of this function when
60
+ # called without an open transaction.
61
+ #
62
+ # Must be one of: {RAISE}, {EXECUTE}, or {WARN_AND_EXECUTE}.
63
+ #
64
+ # @param callback [#call] Callback to be executed
65
+ # @return void
66
+ def before_commit(
67
+ connection: ActiveRecord::Base.connection,
68
+ without_tx: WARN_AND_EXECUTE,
69
+ &callback
70
70
  )
71
- end
71
+ if ActiveRecord::VERSION::MAJOR < 5
72
+ raise NotImplementedError, "#{__method__} works only with Rails 5.0+"
73
+ end
72
74
 
73
- class << self
74
- def register_callback(connection:, name:, no_tx_action:, callback:)
75
+ register_callback(
76
+ connection: connection,
77
+ name: __method__,
78
+ callback: callback,
79
+ without_tx: without_tx,
80
+ )
81
+ end
82
+
83
+ # Runs +callback+ after rolling back of transaction or savepoint (if declared
84
+ # in nested transaction) for database +connection+.
85
+ #
86
+ # Caveat: do not raise +ActivRecord::Rollback+ in nested transaction block!
87
+ # See http://api.rubyonrails.org/classes/ActiveRecord/Transactions/ClassMethods.html#module-ActiveRecord::Transactions::ClassMethods-label-Nested+transactions
88
+ #
89
+ # @param connection [ActiveRecord::ConnectionAdapters::AbstractAdapter]
90
+ # @param callback [#call] Callback to be executed
91
+ # @return void
92
+ # @raise [NotInTransaction] if called outside transaction.
93
+ def after_rollback(connection: ActiveRecord::Base.connection, &callback)
94
+ register_callback(
95
+ connection: connection,
96
+ name: __method__,
97
+ callback: callback,
98
+ without_tx: RAISE,
99
+ )
100
+ end
101
+
102
+ # @api private
103
+ def register_callback(connection:, name:, without_tx:, callback:)
75
104
  raise ArgumentError, "Provide callback to #{name}" unless callback
76
105
 
77
106
  unless in_transaction?(connection)
78
- case no_tx_action
79
- when :warn_and_execute
107
+ case without_tx
108
+ when WARN_AND_EXECUTE
80
109
  warn "#{name}: No transaction open. Executing callback immediately."
81
110
  return callback.call
82
- when :execute
111
+ when EXECUTE
83
112
  return callback.call
84
- when :exception
113
+ when RAISE
85
114
  raise NotInTransaction, "#{name} is useless outside transaction"
115
+ else
116
+ raise ArgumentError, "Invalid \"without_tx\": \"#{without_tx}\""
86
117
  end
87
118
  end
88
119
  wrap = Wrap.new(connection: connection, "#{name}": callback)
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.5
4
+ version: 1.2.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: 2020-03-22 00:00:00.000000000 Z
11
+ date: 2022-03-26 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
@@ -56,16 +70,16 @@ dependencies:
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
@@ -142,14 +156,14 @@ dependencies:
142
156
  requirements:
143
157
  - - "~>"
144
158
  - !ruby/object:Gem::Version
145
- version: '0.80'
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.80'
166
+ version: 0.81.0
153
167
  - !ruby/object:Gem::Dependency
154
168
  name: sqlite3
155
169
  requirement: !ruby/object:Gem::Requirement
@@ -178,10 +192,11 @@ executables: []
178
192
  extensions: []
179
193
  extra_rdoc_files: []
180
194
  files:
195
+ - ".github/workflows/release.yml"
196
+ - ".github/workflows/test.yml"
181
197
  - ".gitignore"
182
198
  - ".rspec"
183
199
  - ".rubocop.yml"
184
- - ".travis.yml"
185
200
  - Appraisals
186
201
  - CHANGELOG.md
187
202
  - Gemfile
@@ -198,6 +213,8 @@ files:
198
213
  - gemfiles/activerecord_5_1.gemfile
199
214
  - gemfiles/activerecord_5_2.gemfile
200
215
  - gemfiles/activerecord_6_0.gemfile
216
+ - gemfiles/activerecord_6_1.gemfile
217
+ - gemfiles/activerecord_7_0.gemfile
201
218
  - gemfiles/activerecord_master.gemfile
202
219
  - lib/after_commit_everywhere.rb
203
220
  - lib/after_commit_everywhere/version.rb
@@ -222,7 +239,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
222
239
  - !ruby/object:Gem::Version
223
240
  version: '0'
224
241
  requirements: []
225
- rubygems_version: 3.1.2
242
+ rubygems_version: 3.1.6
226
243
  signing_key:
227
244
  specification_version: 4
228
245
  summary: Executes code after database commit wherever you want in your application
data/.travis.yml DELETED
@@ -1,29 +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.3.8
15
- gemfile: gemfiles/activerecord_4_2.gemfile
16
- - rvm: 2.4.9
17
- gemfile: gemfiles/activerecord_5_0.gemfile
18
- - rvm: 2.5.7
19
- gemfile: gemfiles/activerecord_5_1.gemfile
20
- - rvm: 2.6.5
21
- gemfile: gemfiles/activerecord_5_2.gemfile
22
- - rvm: 2.7.0
23
- gemfile: gemfiles/activerecord_6_0.gemfile
24
- - rvm: 2.7.0
25
- gemfile: gemfiles/activerecord_master.gemfile
26
-
27
- before_install:
28
- - gem update --system
29
- - gem install bundler -v "~> 2.0"