discard 1.4.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0626ecc4ddd0c4d8e9fb8c9c0edbd42aa664576cbea51403d904c58cb4857c2b
4
- data.tar.gz: 8ec497ce993f3fe49c5ea802021e45b8c04c43b97b5ebd5bc19deb5e91da8843
3
+ metadata.gz: c6e47444b3cac75169be133384030483a8ef0a7821a0ee91cce049f63887ebc3
4
+ data.tar.gz: 28ce8969c023827f43f63a84725291569bde03a0b8e25a8f453a1eed6d8b9dfa
5
5
  SHA512:
6
- metadata.gz: 10c74db9ce658b50d0b2112e34c901a06e69db789d74842400e4b9a9c32ae92b390a67ed6fc189b262d82de8eddeea3e71d85048ce43fbb7a223d758af768b40
7
- data.tar.gz: bb82e531e3098c835bfcbbf1aabf8d06b1356346b1eeee361f01080b4c0d5c3d682f0987c1959588c84fea44769f32f4da6db4916430f656516d4872951b1a53
6
+ metadata.gz: 2562f3ccf49e8622634e375d2cdcb3dd88099e22c311ca0410a979e183d66650b1cc57532ab0ed7f432d3b48facb5dc77892c4403d9dba9ebad26f88222559ed
7
+ data.tar.gz: c3bb81d6967865a8b66552d78e452016fcce882eb327bb0bb9c08a36db42f09becb88e4f6c98194e651fb579daef28d2ae426b3b4feb54deb770df78437151c4
@@ -16,7 +16,16 @@ jobs:
16
16
  fail-fast: false
17
17
  matrix:
18
18
  include:
19
- - rails_version: 8.0.0.rc1
19
+ - rails_version: ~> 8.1.0
20
+ ruby_version: '4.0'
21
+ sqlite_version: ~> 2.0
22
+ - rails_version: ~> 8.1.0
23
+ ruby_version: '3.4'
24
+ sqlite_version: ~> 2.0
25
+ - rails_version: ~> 8.0.0
26
+ ruby_version: '3.4'
27
+ sqlite_version: ~> 2.0
28
+ - rails_version: ~> 8.0.0
20
29
  ruby_version: '3.3'
21
30
  sqlite_version: ~> 2.0
22
31
  - rails_version: ~> 7.2.0
@@ -25,23 +34,17 @@ jobs:
25
34
  - rails_version: ~> 7.2.0
26
35
  ruby_version: '3.2'
27
36
  sqlite_version: ~> 2.0
28
- - rails_version: ~> 7.2.0
29
- ruby_version: '3.1'
30
- sqlite_version: ~> 2.0
31
37
  - rails_version: ~> 7.1.0
32
38
  ruby_version: '3.3'
33
39
  sqlite_version: ~> 1.0
34
40
  - rails_version: ~> 7.0.0
35
41
  ruby_version: '3.2'
36
42
  sqlite_version: ~> 1.0
37
- - rails_version: ~> 6.1.0
38
- ruby_version: '3.0'
39
- sqlite_version: ~> 1.0
40
43
  env:
41
44
  RAILS_VERSION: ${{ matrix.rails_version }}
42
45
  SQLITE_VERSION: ${{ matrix.sqlite_version }}
43
46
  steps:
44
- - uses: actions/checkout@v4
47
+ - uses: actions/checkout@v6
45
48
  - uses: ruby/setup-ruby@v1
46
49
  with:
47
50
  ruby-version: ${{ matrix.ruby_version }}
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 4.0.1
data/CHANGELOG.md CHANGED
@@ -1,4 +1,8 @@
1
- ### Unreleased
1
+ ### Version 2.0.0
2
+ Release date: 2026-05-27
3
+
4
+ * Require ActiveRecord >= 7.0; drop support for Rails 6.x and earlier
5
+ * Wrap `#discard` / `#undiscard` in a transaction so callback exceptions roll back the DB write (#84, #77)
2
6
 
3
7
  ### Version 1.4.0
4
8
  Release date: 2024-11-05
data/Gemfile CHANGED
@@ -3,6 +3,10 @@ source 'https://rubygems.org'
3
3
  rails_version = ENV['RAILS_VERSION']
4
4
  gem 'activerecord', rails_version
5
5
 
6
+ if rails_version == '~> 6.1.0'
7
+ gem 'concurrent-ruby', '1.3.4'
8
+ end
9
+
6
10
  if sqlite_version = ENV['SQLITE_VERSION']
7
11
  gem 'sqlite3', sqlite_version
8
12
  end
data/README.md CHANGED
@@ -13,7 +13,7 @@ A simple ActiveRecord mixin to add conventions for flagging records as discarded
13
13
  Add this line to your application's Gemfile:
14
14
 
15
15
  ```ruby
16
- gem 'discard', '~> 1.4'
16
+ gem 'discard', '~> 2.0'
17
17
  ```
18
18
 
19
19
  And then execute:
@@ -33,6 +33,7 @@ end
33
33
  ```
34
34
 
35
35
  You can either generate a migration using:
36
+
36
37
  ```
37
38
  rails generate migration add_discarded_at_to_posts discarded_at:datetime:index
38
39
  ```
@@ -47,7 +48,6 @@ class AddDiscardToPosts < ActiveRecord::Migration[5.0]
47
48
  end
48
49
  ```
49
50
 
50
-
51
51
  #### Discard a record
52
52
 
53
53
  ```ruby
@@ -200,10 +200,15 @@ class Post < ActiveRecord::Base
200
200
  end
201
201
  ```
202
202
 
203
- *Warning:* Please note that callbacks for save and update are run when discarding/undiscarding a record
203
+ Some important things to note:
204
+
205
+ - Callbacks for save and update are run when discarding/undiscarding a record.
206
+ - Validations are not run during `#discard` or `#undiscard`. The column is updated via `update_attribute`, which skips validations.
207
+ - The discard column is also flipped *between* the `before_` and `after_` callbacks, so `before_discard` sees `discarded?` as `false` while `after_discard` sees it as `true` (and symmetrically for undiscard). Callbacks gated on `if: :discarded?` will fire accordingly, which is useful when a callback should only run on one side of the transition.
204
208
 
205
209
 
206
210
  #### Performance tuning
211
+
207
212
  `discard_all` and `undiscard_all` is intended to behave like `destroy_all` which has callbacks, validations, and does one query per record. If performance is a big concern, you may consider replacing it with:
208
213
 
209
214
  `scope.update_all(discarded_at: Time.current)`
@@ -269,7 +274,7 @@ You can find more information about the history and purpose of Discard in [this
269
274
 
270
275
  ## Development
271
276
 
272
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
277
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
273
278
 
274
279
  ## Contributing
275
280
 
data/discard.gemspec CHANGED
@@ -22,10 +22,10 @@ Gem::Specification.new do |spec|
22
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
23
  spec.require_paths = ["lib"]
24
24
 
25
- spec.add_dependency "activerecord", ">= 4.2", "< 9.0"
25
+ spec.add_dependency "activerecord", ">= 7.0", "< 9.0"
26
26
  spec.add_development_dependency "bundler"
27
27
  spec.add_development_dependency "rake", ">= 10.0"
28
- spec.add_development_dependency "rspec", "~> 3.5.0"
28
+ spec.add_development_dependency "rspec", "~> 3.13"
29
29
  spec.add_development_dependency "database_cleaner", "~> 1.5"
30
30
  spec.add_development_dependency "with_model", "~> 2.0"
31
31
  spec.add_development_dependency "sqlite3"
data/lib/discard/model.rb CHANGED
@@ -117,8 +117,11 @@ module Discard
117
117
  # @return [Boolean] true if successful, otherwise false
118
118
  def discard
119
119
  return false if discarded?
120
- run_callbacks(:discard) do
121
- update_attribute(self.class.discard_column, Time.current)
120
+
121
+ with_transaction_returning_status do
122
+ run_callbacks(:discard) do
123
+ update_attribute(self.class.discard_column, Time.current)
124
+ end
122
125
  end
123
126
  end
124
127
 
@@ -139,8 +142,11 @@ module Discard
139
142
  # @return [Boolean] true if successful, otherwise false
140
143
  def undiscard
141
144
  return false unless discarded?
142
- run_callbacks(:undiscard) do
143
- update_attribute(self.class.discard_column, nil)
145
+
146
+ with_transaction_returning_status do
147
+ run_callbacks(:undiscard) do
148
+ update_attribute(self.class.discard_column, nil)
149
+ end
144
150
  end
145
151
  end
146
152
 
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Discard
4
4
  # Discard version
5
- VERSION = "1.4.0".freeze
5
+ VERSION = "2.0.0".freeze
6
6
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: discard
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Hawthorn
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2024-11-05 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: activerecord
@@ -16,7 +15,7 @@ dependencies:
16
15
  requirements:
17
16
  - - ">="
18
17
  - !ruby/object:Gem::Version
19
- version: '4.2'
18
+ version: '7.0'
20
19
  - - "<"
21
20
  - !ruby/object:Gem::Version
22
21
  version: '9.0'
@@ -26,7 +25,7 @@ dependencies:
26
25
  requirements:
27
26
  - - ">="
28
27
  - !ruby/object:Gem::Version
29
- version: '4.2'
28
+ version: '7.0'
30
29
  - - "<"
31
30
  - !ruby/object:Gem::Version
32
31
  version: '9.0'
@@ -64,14 +63,14 @@ dependencies:
64
63
  requirements:
65
64
  - - "~>"
66
65
  - !ruby/object:Gem::Version
67
- version: 3.5.0
66
+ version: '3.13'
68
67
  type: :development
69
68
  prerelease: false
70
69
  version_requirements: !ruby/object:Gem::Requirement
71
70
  requirements:
72
71
  - - "~>"
73
72
  - !ruby/object:Gem::Version
74
- version: 3.5.0
73
+ version: '3.13'
75
74
  - !ruby/object:Gem::Dependency
76
75
  name: database_cleaner
77
76
  requirement: !ruby/object:Gem::Requirement
@@ -128,6 +127,7 @@ files:
128
127
  - ".github/workflows/test.yml"
129
128
  - ".gitignore"
130
129
  - ".rspec"
130
+ - ".ruby-version"
131
131
  - ".yardopts"
132
132
  - CHANGELOG.md
133
133
  - CODE_OF_CONDUCT.md
@@ -146,7 +146,6 @@ homepage: https://github.com/jhawthorn/discard
146
146
  licenses:
147
147
  - MIT
148
148
  metadata: {}
149
- post_install_message:
150
149
  rdoc_options: []
151
150
  require_paths:
152
151
  - lib
@@ -161,8 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
161
160
  - !ruby/object:Gem::Version
162
161
  version: '0'
163
162
  requirements: []
164
- rubygems_version: 3.5.16
165
- signing_key:
163
+ rubygems_version: 3.6.9
166
164
  specification_version: 4
167
165
  summary: ActiveRecord soft-deletes done right
168
166
  test_files: []