after_commit_everywhere 0.1.1 → 1.0.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: 208fab154c7355e827669ffb9943b8dd9d320ec8096284f4a35bfff45b5d6301
4
- data.tar.gz: 95989a3e5c164f21371ccd8102e2d51ba99c4b303a956c83fde73b733fce700a
3
+ metadata.gz: b8b2847b6af9346bd5c042b364ccc1d94bbb696d82ef118362ad8085c2a96715
4
+ data.tar.gz: b0089a18d4087f800e161477678a8dd69871d2413801e33556751a5e7d6731f4
5
5
  SHA512:
6
- metadata.gz: 7bdad3cb3d1e23a2ee124e06a43340c0fe6af8737d1e59e276aec40277ffb3cc662b4ec2de7856154dfb914ae69b97ca3aa977c87bf888f60367a5cf86a169a3
7
- data.tar.gz: 7be979c08769da19778405d59d4808b0e402ff5d943c6ed541026056d8eea005fc6df98b41730b04de2f2f188256ade720726dbd09f5c75306faaa875bdd4b8b
6
+ metadata.gz: 2c8342d72f9a2d076d62f52842aff823cdef8a8024e23f45c3360fdb662338878258efde0e2f09fe1f471d5830ed068d723af46f3ac628ef62daea843efdc723
7
+ data.tar.gz: b6a74ddc5d7e8f34db311fd44d9b88627c2213c70931e6ebaf635f64cc74a3051724af088b4c2ba04f4420b856779626a1fbab2bc0f07c2c9c22168f5a9ff779
@@ -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
 
@@ -34,8 +36,26 @@ Style/TrailingCommaInArguments:
34
36
  Enabled: true
35
37
  EnforcedStyleForMultiline: consistent_comma
36
38
 
37
- Style/TrailingCommaInLiteral:
38
- Description: 'Checks for trailing comma in array and hash literals.'
39
+ Style/TrailingCommaInArrayLiteral:
40
+ Description: 'Checks for trailing comma in array literals.'
41
+ StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas'
42
+ Enabled: true
43
+ EnforcedStyleForMultiline: consistent_comma
44
+
45
+ Style/TrailingCommaInHashLiteral:
46
+ Description: 'Checks for trailing comma in hash literals.'
39
47
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas'
40
48
  Enabled: true
41
49
  EnforcedStyleForMultiline: consistent_comma
50
+
51
+ Style/StringLiterals:
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
@@ -1,17 +1,45 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- appraise 'activerecord-5-0' do
4
- gem 'activerecord', '~> 5.0.0'
3
+ appraise "activerecord-4-2" do
4
+ gem "activerecord", "~> 4.2.0"
5
+ gem "sqlite3", "~> 1.3.6"
5
6
  end
6
7
 
7
- appraise 'activerecord-5-1' do
8
- gem 'activerecord', '~> 5.1.0'
8
+ appraise "activerecord-5-0" do
9
+ gem "activerecord", "~> 5.0.0"
10
+ gem "sqlite3", "~> 1.3.6"
9
11
  end
10
12
 
11
- appraise 'activerecord-5-2' do
12
- gem 'activerecord', '~> 5.2.0.rc1'
13
+ appraise "activerecord-5-1" do
14
+ gem "activerecord", "~> 5.1.0"
15
+ gem "sqlite3", "~> 1.3", ">= 1.3.6"
13
16
  end
14
17
 
15
- appraise 'activerecord-master' do
16
- gem 'activerecord', git: 'https://github.com/rails/rails.git'
18
+ appraise "activerecord-5-2" do
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"
32
+ end
33
+
34
+ appraise "activerecord-master" do
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"
42
+
43
+ # See https://github.com/cgriego/active_attr/pull/183
44
+ gem "active_attr", git: "https://github.com/Envek/active_attr.git", branch: "chore/loose-dependency-constraint"
17
45
  end
data/CHANGELOG.md ADDED
@@ -0,0 +1,44 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5
+ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [Unreleased]
8
+
9
+ ## 1.0.0 (2021-02-17)
10
+
11
+ Declare gem as stable. No changes since 0.1.5.
12
+
13
+ See [#11](https://github.com/Envek/after_commit_everywhere/issues/11) for discussion.
14
+
15
+ ## 0.1.5 (2020-03-22)
16
+
17
+ ### Fixed
18
+
19
+ - [PR [#8](https://github.com/Envek/after_commit_everywhere/pull/8)] Callback registration when callback methods are aliased. ([@stokarenko])
20
+
21
+ ## 0.1.4 (2019-09-10)
22
+
23
+ - [PR [#6](https://github.com/Envek/after_commit_everywhere/pull/6)] ActiveRecord 6.0 compatibility. ([@joevandyk])
24
+
25
+ ## 0.1.3 (2019-02-18)
26
+
27
+ - Make `in_transaction?` helper method public. ([@Envek])
28
+
29
+ ## 0.1.2 (2018-05-01)
30
+
31
+ - [PR [#1](https://github.com/Envek/after_commit_everywhere/pull/1)] Enable ActiveRecord 4.2 support. ([@arjun810], [@Envek])
32
+
33
+ ## 0.1.1 (2018-03-29)
34
+
35
+ - Do not issue warning on `after_commit` invocation outside of transaction as it is expected behaviour. ([@Envek])
36
+
37
+ ## 0.1.0 (2018-03-18)
38
+
39
+ - Initial version with `after_commit`, `before_commit`. and `after_rollback` callbacks. ([@Envek])
40
+
41
+ [@Envek]: https://github.com/Envek "Andrey Novikov"
42
+ [@arjun810]: https://github.com/arjun810 "Arjun Singh"
43
+ [@joevandyk]: https://github.com/joevandyk "Joe Van Dyk"
44
+ [@stokarenko]: https://github.com/stokarenko "Sergey Tokarenko"
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- source 'https://rubygems.org'
3
+ source "https://rubygems.org"
4
4
 
5
5
  git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
6
 
data/Gemfile.lock ADDED
@@ -0,0 +1,216 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ after_commit_everywhere (0.1.5)
5
+ activerecord (>= 4.2)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actioncable (6.1.2.1)
11
+ actionpack (= 6.1.2.1)
12
+ activesupport (= 6.1.2.1)
13
+ nio4r (~> 2.0)
14
+ websocket-driver (>= 0.6.1)
15
+ actionmailbox (6.1.2.1)
16
+ actionpack (= 6.1.2.1)
17
+ activejob (= 6.1.2.1)
18
+ activerecord (= 6.1.2.1)
19
+ activestorage (= 6.1.2.1)
20
+ activesupport (= 6.1.2.1)
21
+ mail (>= 2.7.1)
22
+ actionmailer (6.1.2.1)
23
+ actionpack (= 6.1.2.1)
24
+ actionview (= 6.1.2.1)
25
+ activejob (= 6.1.2.1)
26
+ activesupport (= 6.1.2.1)
27
+ mail (~> 2.5, >= 2.5.4)
28
+ rails-dom-testing (~> 2.0)
29
+ actionpack (6.1.2.1)
30
+ actionview (= 6.1.2.1)
31
+ activesupport (= 6.1.2.1)
32
+ rack (~> 2.0, >= 2.0.9)
33
+ rack-test (>= 0.6.3)
34
+ rails-dom-testing (~> 2.0)
35
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
36
+ actiontext (6.1.2.1)
37
+ actionpack (= 6.1.2.1)
38
+ activerecord (= 6.1.2.1)
39
+ activestorage (= 6.1.2.1)
40
+ activesupport (= 6.1.2.1)
41
+ nokogiri (>= 1.8.5)
42
+ actionview (6.1.2.1)
43
+ activesupport (= 6.1.2.1)
44
+ builder (~> 3.1)
45
+ erubi (~> 1.4)
46
+ rails-dom-testing (~> 2.0)
47
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
48
+ active_attr (0.15.1)
49
+ actionpack (>= 3.0.2, < 6.2)
50
+ activemodel (>= 3.0.2, < 6.2)
51
+ activesupport (>= 3.0.2, < 6.2)
52
+ activejob (6.1.2.1)
53
+ activesupport (= 6.1.2.1)
54
+ globalid (>= 0.3.6)
55
+ activemodel (6.1.2.1)
56
+ activesupport (= 6.1.2.1)
57
+ activerecord (6.1.2.1)
58
+ activemodel (= 6.1.2.1)
59
+ activesupport (= 6.1.2.1)
60
+ activestorage (6.1.2.1)
61
+ actionpack (= 6.1.2.1)
62
+ activejob (= 6.1.2.1)
63
+ activerecord (= 6.1.2.1)
64
+ activesupport (= 6.1.2.1)
65
+ marcel (~> 0.3.1)
66
+ mimemagic (~> 0.3.2)
67
+ activesupport (6.1.2.1)
68
+ concurrent-ruby (~> 1.0, >= 1.0.2)
69
+ i18n (>= 1.6, < 2)
70
+ minitest (>= 5.1)
71
+ tzinfo (~> 2.0)
72
+ zeitwerk (~> 2.3)
73
+ anyway_config (2.1.0)
74
+ ruby-next-core (>= 0.11.0)
75
+ appraisal (2.3.0)
76
+ bundler
77
+ rake
78
+ thor (>= 0.14.0)
79
+ ast (2.4.2)
80
+ builder (3.2.4)
81
+ coderay (1.1.3)
82
+ concurrent-ruby (1.1.8)
83
+ crass (1.0.6)
84
+ diff-lcs (1.4.4)
85
+ erubi (1.10.0)
86
+ globalid (0.4.2)
87
+ activesupport (>= 4.2.0)
88
+ i18n (1.8.9)
89
+ concurrent-ruby (~> 1.0)
90
+ isolator (0.7.0)
91
+ sniffer (>= 0.3.1)
92
+ jaro_winkler (1.5.4)
93
+ loofah (2.9.0)
94
+ crass (~> 1.0.2)
95
+ nokogiri (>= 1.5.9)
96
+ mail (2.7.1)
97
+ mini_mime (>= 0.1.1)
98
+ marcel (0.3.3)
99
+ mimemagic (~> 0.3.2)
100
+ method_source (1.0.0)
101
+ mimemagic (0.3.5)
102
+ mini_mime (1.0.2)
103
+ mini_portile2 (2.5.0)
104
+ minitest (5.14.3)
105
+ nio4r (2.5.5)
106
+ nokogiri (1.11.1)
107
+ mini_portile2 (~> 2.5.0)
108
+ racc (~> 1.4)
109
+ parallel (1.20.1)
110
+ parser (3.0.0.0)
111
+ ast (~> 2.4.1)
112
+ pry (0.14.0)
113
+ coderay (~> 1.1)
114
+ method_source (~> 1.0)
115
+ racc (1.5.2)
116
+ rack (2.2.3)
117
+ rack-test (1.1.0)
118
+ rack (>= 1.0, < 3)
119
+ rails (6.1.2.1)
120
+ actioncable (= 6.1.2.1)
121
+ actionmailbox (= 6.1.2.1)
122
+ actionmailer (= 6.1.2.1)
123
+ actionpack (= 6.1.2.1)
124
+ actiontext (= 6.1.2.1)
125
+ actionview (= 6.1.2.1)
126
+ activejob (= 6.1.2.1)
127
+ activemodel (= 6.1.2.1)
128
+ activerecord (= 6.1.2.1)
129
+ activestorage (= 6.1.2.1)
130
+ activesupport (= 6.1.2.1)
131
+ bundler (>= 1.15.0)
132
+ railties (= 6.1.2.1)
133
+ sprockets-rails (>= 2.0.0)
134
+ rails-dom-testing (2.0.3)
135
+ activesupport (>= 4.2.0)
136
+ nokogiri (>= 1.6)
137
+ rails-html-sanitizer (1.3.0)
138
+ loofah (~> 2.3)
139
+ railties (6.1.2.1)
140
+ actionpack (= 6.1.2.1)
141
+ activesupport (= 6.1.2.1)
142
+ method_source
143
+ rake (>= 0.8.7)
144
+ thor (~> 1.0)
145
+ rainbow (3.0.0)
146
+ rake (13.0.3)
147
+ rexml (3.2.4)
148
+ rspec (3.10.0)
149
+ rspec-core (~> 3.10.0)
150
+ rspec-expectations (~> 3.10.0)
151
+ rspec-mocks (~> 3.10.0)
152
+ rspec-core (3.10.1)
153
+ rspec-support (~> 3.10.0)
154
+ rspec-expectations (3.10.1)
155
+ diff-lcs (>= 1.2.0, < 2.0)
156
+ rspec-support (~> 3.10.0)
157
+ rspec-mocks (3.10.2)
158
+ diff-lcs (>= 1.2.0, < 2.0)
159
+ rspec-support (~> 3.10.0)
160
+ rspec-rails (4.0.2)
161
+ actionpack (>= 4.2)
162
+ activesupport (>= 4.2)
163
+ railties (>= 4.2)
164
+ rspec-core (~> 3.10)
165
+ rspec-expectations (~> 3.10)
166
+ rspec-mocks (~> 3.10)
167
+ rspec-support (~> 3.10)
168
+ rspec-support (3.10.2)
169
+ rubocop (0.81.0)
170
+ jaro_winkler (~> 1.5.1)
171
+ parallel (~> 1.10)
172
+ parser (>= 2.7.0.1)
173
+ rainbow (>= 2.2.2, < 4.0)
174
+ rexml
175
+ ruby-progressbar (~> 1.7)
176
+ unicode-display_width (>= 1.4.0, < 2.0)
177
+ ruby-next-core (0.12.0)
178
+ ruby-progressbar (1.11.0)
179
+ sniffer (0.4.0)
180
+ active_attr (>= 0.10.2)
181
+ anyway_config (>= 1.0)
182
+ sprockets (4.0.2)
183
+ concurrent-ruby (~> 1.0)
184
+ rack (> 1, < 3)
185
+ sprockets-rails (3.2.2)
186
+ actionpack (>= 4.0)
187
+ activesupport (>= 4.0)
188
+ sprockets (>= 3.0.0)
189
+ sqlite3 (1.4.2)
190
+ thor (1.1.0)
191
+ tzinfo (2.0.4)
192
+ concurrent-ruby (~> 1.0)
193
+ unicode-display_width (1.7.0)
194
+ websocket-driver (0.7.3)
195
+ websocket-extensions (>= 0.1.0)
196
+ websocket-extensions (0.1.5)
197
+ zeitwerk (2.4.2)
198
+
199
+ PLATFORMS
200
+ ruby
201
+
202
+ DEPENDENCIES
203
+ after_commit_everywhere!
204
+ appraisal
205
+ bundler (~> 2.0)
206
+ isolator (~> 0.7)
207
+ pry
208
+ rails
209
+ rake (~> 13.0)
210
+ rspec (~> 3.0)
211
+ rspec-rails
212
+ rubocop (~> 0.81.0)
213
+ sqlite3 (~> 1.3, >= 1.3.6)
214
+
215
+ BUNDLED WITH
216
+ 2.2.9
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>
@@ -98,6 +97,8 @@ Will be executed right before outermost transaction will be commited _(I can't i
98
97
 
99
98
  If called outside transaction will execute callback immediately.
100
99
 
100
+ Supported only starting from ActiveRecord 5.0.
101
+
101
102
  #### `after_rollback`
102
103
 
103
104
  Will be executed right after transaction in which it have been declared was rolled back (this might be nested savepoint transaction block with `requires_new: true`).
@@ -110,14 +111,65 @@ Please keep in mind ActiveRecord's [limitations for rolling back nested transact
110
111
 
111
112
  #### Does it works with transactional_test or DatabaseCleaner
112
113
 
113
- *Yes* but currently it is not tested (help wanted).
114
+ **Yes**.
115
+
116
+ ### Be aware of mental traps
117
+
118
+ 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.
119
+
120
+ So, **DO NOT DO THIS**:
121
+
122
+ ```ruby
123
+ class Post < ActiveRecord::Base
124
+ def self.bulk_ops
125
+ find_each do
126
+ after_commit { raise "Some doesn't expect that this screw up everything, but they should" }
127
+ end
128
+ end
129
+ end
130
+ ```
131
+
132
+ 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.
114
133
 
134
+ See https://github.com/Envek/after_commit_everywhere/issues/13 for details.
115
135
 
116
136
  ## Development
117
137
 
118
138
  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.
119
139
 
120
- 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).
140
+ To install this gem onto your local machine, run `bundle exec rake install`.
141
+
142
+ ### Releasing new versions
143
+
144
+ 1. Bump version number in `lib/after_commit_everywhere/version.rb`
145
+
146
+ 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`
147
+
148
+ 2. Fill `CHANGELOG.md` with missing changes, add header with version and date.
149
+
150
+ 3. Make a commit:
151
+
152
+ ```sh
153
+ git add lib/after_commit_everywhere/version.rb CHANGELOG.md
154
+ version=$(ruby -r ./lib/after_commit_everywhere/version.rb -e "puts Gem::Version.new(AfterCommitEverywhere::VERSION)")
155
+ git commit --message="${version}: " --edit
156
+ ```
157
+
158
+ 4. Create annotated tag:
159
+
160
+ ```sh
161
+ git tag v${version} --annotate --message="${version}: " --edit --sign
162
+ ```
163
+
164
+ 5. Fill version name into subject line and (optionally) some description (list of changes will be taken from `CHANGELOG.md` and appended automatically)
165
+
166
+ 6. Push it:
167
+
168
+ ```sh
169
+ git push --follow-tags
170
+ ```
171
+
172
+ 7. GitHub Actions will create a new release, build and push gem into [rubygems.org](https://rubygems.org)! You're done!
121
173
 
122
174
 
123
175
  ## Contributing
data/Rakefile CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'bundler/gem_tasks'
4
- require 'rspec/core/rake_task'
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
5
 
6
6
  RSpec::Core::RakeTask.new(:spec)
7
7
 
@@ -1,14 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- lib = File.expand_path('../lib', __FILE__)
3
+ lib = File.expand_path("lib", __dir__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
- require 'after_commit_everywhere/version'
5
+ require "after_commit_everywhere/version"
6
6
 
7
7
  Gem::Specification.new do |spec|
8
- spec.name = 'after_commit_everywhere'
8
+ spec.name = "after_commit_everywhere"
9
9
  spec.version = AfterCommitEverywhere::VERSION
10
- spec.authors = ['Andrey Novikov']
11
- spec.email = ['envek@envek.name']
10
+ spec.authors = ["Andrey Novikov"]
11
+ spec.email = ["envek@envek.name"]
12
12
 
13
13
  spec.summary = <<~MSG.strip
14
14
  Executes code after database commit wherever you want in your application
@@ -18,22 +18,25 @@ Gem::Specification.new do |spec|
18
18
  Brings before_commit, after_commit, and after_rollback transactional \
19
19
  callbacks outside of your ActiveRecord models.
20
20
  MSG
21
- spec.homepage = 'https://github.com/Envek/after_commit_everywhere'
22
- spec.license = 'MIT'
21
+ spec.homepage = "https://github.com/Envek/after_commit_everywhere"
22
+ spec.license = "MIT"
23
23
 
24
24
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
25
25
  f.match(%r{^(test|spec|features)/})
26
26
  end
27
- spec.bindir = 'exe'
27
+ spec.bindir = "exe"
28
28
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
- spec.require_paths = ['lib']
29
+ spec.require_paths = ["lib"]
30
30
 
31
- spec.add_dependency 'activerecord', '>= 5.0'
32
- spec.add_development_dependency 'appraisal'
33
- spec.add_development_dependency 'bundler', '~> 1.16'
34
- spec.add_development_dependency 'pry'
35
- spec.add_development_dependency 'rake', '~> 10.0'
36
- spec.add_development_dependency 'rspec', '~> 3.0'
37
- spec.add_development_dependency 'rubocop'
38
- spec.add_development_dependency 'sqlite3'
31
+ spec.add_dependency "activerecord", ">= 4.2"
32
+ spec.add_development_dependency "appraisal"
33
+ spec.add_development_dependency "bundler", "~> 2.0"
34
+ spec.add_development_dependency "isolator", "~> 0.7"
35
+ spec.add_development_dependency "pry"
36
+ spec.add_development_dependency "rails"
37
+ spec.add_development_dependency "rake", "~> 13.0"
38
+ spec.add_development_dependency "rspec", "~> 3.0"
39
+ spec.add_development_dependency "rspec-rails"
40
+ spec.add_development_dependency "rubocop", "~> 0.81.0"
41
+ spec.add_development_dependency "sqlite3", "~> 1.3", ">= 1.3.6"
39
42
  end
data/bin/console CHANGED
@@ -1,11 +1,11 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'bundler/setup'
5
- require 'after_commit_everywhere'
4
+ require "bundler/setup"
5
+ require "after_commit_everywhere"
6
6
 
7
7
  # You can add fixtures and/or initialization code here to make experimenting
8
8
  # with your gem easier. You can also use a different console, if you like.
9
9
 
10
- require 'pry'
10
+ require "pry"
11
11
  Pry.start
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 4.2.0"
6
+ gem "sqlite3", "~> 1.3.6"
7
+
8
+ gemspec path: "../"
@@ -3,5 +3,6 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "activerecord", "~> 5.0.0"
6
+ gem "sqlite3", "~> 1.3.6"
6
7
 
7
8
  gemspec path: "../"
@@ -3,5 +3,6 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "activerecord", "~> 5.1.0"
6
+ gem "sqlite3", "~> 1.3", ">= 1.3.6"
6
7
 
7
8
  gemspec path: "../"
@@ -2,6 +2,7 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "activerecord", "~> 5.2.0.rc1"
5
+ gem "activerecord", "~> 5.2.0"
6
+ gem "sqlite3", "~> 1.3", ">= 1.3.6"
6
7
 
7
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: "../"
@@ -2,6 +2,13 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- 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
+
10
+ gem "sqlite3", "~> 1.4"
11
+ gem "rspec-rails", "~> 4.0"
12
+ gem "active_attr", git: "https://github.com/Envek/active_attr.git", branch: "chore/loose-dependency-constraint"
6
13
 
7
14
  gemspec path: "../"
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'active_record'
3
+ require "active_record"
4
4
 
5
- require 'after_commit_everywhere/version'
6
- require 'after_commit_everywhere/wrap'
5
+ require "after_commit_everywhere/version"
6
+ require "after_commit_everywhere/wrap"
7
7
 
8
8
  # Module allowing to use ActiveRecord transactional callbacks outside of
9
9
  # ActiveRecord models, literally everywhere in your application.
@@ -23,7 +23,7 @@ module AfterCommitEverywhere
23
23
  def after_commit(connection: ActiveRecord::Base.connection, &callback)
24
24
  AfterCommitEverywhere.register_callback(
25
25
  connection: connection,
26
- name: __callee__,
26
+ name: __method__,
27
27
  callback: callback,
28
28
  no_tx_action: :execute,
29
29
  )
@@ -33,13 +33,19 @@ module AfterCommitEverywhere
33
33
  #
34
34
  # If called outside transaction it will execute callback immediately.
35
35
  #
36
+ # Available only since Ruby on Rails 5.0. See https://github.com/rails/rails/pull/18936
37
+ #
36
38
  # @param connection [ActiveRecord::ConnectionAdapters::AbstractAdapter]
37
39
  # @param callback [#call] Callback to be executed
38
40
  # @return void
39
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
45
+
40
46
  AfterCommitEverywhere.register_callback(
41
47
  connection: connection,
42
- name: __callee__,
48
+ name: __method__,
43
49
  callback: callback,
44
50
  no_tx_action: :warn_and_execute,
45
51
  )
@@ -58,7 +64,7 @@ module AfterCommitEverywhere
58
64
  def after_rollback(connection: ActiveRecord::Base.connection, &callback)
59
65
  AfterCommitEverywhere.register_callback(
60
66
  connection: connection,
61
- name: __callee__,
67
+ name: __method__,
62
68
  callback: callback,
63
69
  no_tx_action: :exception,
64
70
  )
@@ -67,6 +73,7 @@ module AfterCommitEverywhere
67
73
  class << self
68
74
  def register_callback(connection:, name:, no_tx_action:, callback:)
69
75
  raise ArgumentError, "Provide callback to #{name}" unless callback
76
+
70
77
  unless in_transaction?(connection)
71
78
  case no_tx_action
72
79
  when :warn_and_execute
@@ -82,9 +89,8 @@ module AfterCommitEverywhere
82
89
  connection.add_transaction_record(wrap)
83
90
  end
84
91
 
85
- private
86
-
87
- def in_transaction?(connection)
92
+ # Helper method to determine whether we're currently in transaction or not
93
+ def in_transaction?(connection = ActiveRecord::Base.connection)
88
94
  # service transactions (tests and database_cleaner) are not joinable
89
95
  connection.transaction_open? && connection.current_transaction.joinable?
90
96
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AfterCommitEverywhere
4
- VERSION = '0.1.1'
4
+ VERSION = "1.0.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.1
4
+ version: 1.0.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: 2018-03-29 00:00:00.000000000 Z
11
+ date: 2021-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '5.0'
19
+ version: '4.2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '5.0'
26
+ version: '4.2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: appraisal
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -44,14 +44,28 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '1.16'
47
+ version: '2.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '1.16'
54
+ version: '2.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: isolator
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.7'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.7'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: pry
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -66,20 +80,34 @@ dependencies:
66
80
  - - ">="
67
81
  - !ruby/object:Gem::Version
68
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rails
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
69
97
  - !ruby/object:Gem::Dependency
70
98
  name: rake
71
99
  requirement: !ruby/object:Gem::Requirement
72
100
  requirements:
73
101
  - - "~>"
74
102
  - !ruby/object:Gem::Version
75
- version: '10.0'
103
+ version: '13.0'
76
104
  type: :development
77
105
  prerelease: false
78
106
  version_requirements: !ruby/object:Gem::Requirement
79
107
  requirements:
80
108
  - - "~>"
81
109
  - !ruby/object:Gem::Version
82
- version: '10.0'
110
+ version: '13.0'
83
111
  - !ruby/object:Gem::Dependency
84
112
  name: rspec
85
113
  requirement: !ruby/object:Gem::Requirement
@@ -95,7 +123,7 @@ dependencies:
95
123
  - !ruby/object:Gem::Version
96
124
  version: '3.0'
97
125
  - !ruby/object:Gem::Dependency
98
- name: rubocop
126
+ name: rspec-rails
99
127
  requirement: !ruby/object:Gem::Requirement
100
128
  requirements:
101
129
  - - ">="
@@ -108,34 +136,57 @@ dependencies:
108
136
  - - ">="
109
137
  - !ruby/object:Gem::Version
110
138
  version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rubocop
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: 0.81.0
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: 0.81.0
111
153
  - !ruby/object:Gem::Dependency
112
154
  name: sqlite3
113
155
  requirement: !ruby/object:Gem::Requirement
114
156
  requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '1.3'
115
160
  - - ">="
116
161
  - !ruby/object:Gem::Version
117
- version: '0'
162
+ version: 1.3.6
118
163
  type: :development
119
164
  prerelease: false
120
165
  version_requirements: !ruby/object:Gem::Requirement
121
166
  requirements:
167
+ - - "~>"
168
+ - !ruby/object:Gem::Version
169
+ version: '1.3'
122
170
  - - ">="
123
171
  - !ruby/object:Gem::Version
124
- version: '0'
125
- description: Brings before_commit, after_commit, and after_rollback transactional callbacks
126
- outside of your ActiveRecord models.
172
+ version: 1.3.6
173
+ description: Brings before_commit, after_commit, and after_rollback transactional
174
+ callbacks outside of your ActiveRecord models.
127
175
  email:
128
176
  - envek@envek.name
129
177
  executables: []
130
178
  extensions: []
131
179
  extra_rdoc_files: []
132
180
  files:
181
+ - ".github/workflows/release.yml"
182
+ - ".github/workflows/test.yml"
133
183
  - ".gitignore"
134
184
  - ".rspec"
135
185
  - ".rubocop.yml"
136
- - ".travis.yml"
137
186
  - Appraisals
187
+ - CHANGELOG.md
138
188
  - Gemfile
189
+ - Gemfile.lock
139
190
  - LICENSE.txt
140
191
  - README.md
141
192
  - Rakefile
@@ -143,9 +194,12 @@ files:
143
194
  - bin/console
144
195
  - bin/setup
145
196
  - gemfiles/.bundle/config
197
+ - gemfiles/activerecord_4_2.gemfile
146
198
  - gemfiles/activerecord_5_0.gemfile
147
199
  - gemfiles/activerecord_5_1.gemfile
148
200
  - gemfiles/activerecord_5_2.gemfile
201
+ - gemfiles/activerecord_6_0.gemfile
202
+ - gemfiles/activerecord_6_1.gemfile
149
203
  - gemfiles/activerecord_master.gemfile
150
204
  - lib/after_commit_everywhere.rb
151
205
  - lib/after_commit_everywhere/version.rb
@@ -170,8 +224,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
170
224
  - !ruby/object:Gem::Version
171
225
  version: '0'
172
226
  requirements: []
173
- rubyforge_project:
174
- rubygems_version: 2.7.6
227
+ rubygems_version: 3.1.4
175
228
  signing_key:
176
229
  specification_version: 4
177
230
  summary: Executes code after database commit wherever you want in your application
data/.travis.yml DELETED
@@ -1,25 +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.0
15
- gemfile: gemfiles/activerecord_5_0.gemfile
16
- - rvm: 2.5.0
17
- gemfile: gemfiles/activerecord_5_1.gemfile
18
- - rvm: 2.5.0
19
- gemfile: gemfiles/activerecord_5_2.gemfile
20
- - rvm: 2.5.0
21
- gemfile: gemfiles/activerecord_master.gemfile
22
- - rvm: 2.4.3
23
- gemfile: gemfiles/activerecord_5_2.gemfile
24
- - rvm: 2.3.6
25
- gemfile: gemfiles/activerecord_5_2.gemfile