discard 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/ISSUE_TEMPLATE/bug-report.md +24 -0
- data/.github/ISSUE_TEMPLATE/feature-proposal.md +10 -0
- data/.github/workflows/test.yml +30 -0
- data/.travis.yml +18 -14
- data/CHANGELOG.md +3 -0
- data/README.md +21 -2
- data/lib/discard/model.rb +45 -1
- data/lib/discard/version.rb +1 -1
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1aa5617487d7e2fed08d3afbe5e88e92aaef5371c1678a7f3c4acf532341ab56
|
4
|
+
data.tar.gz: 4f4da23a43a04274325db950a05bbfb3ff478430bea166c5c9d941fb2181769e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96650925ee2f6dd7c348059f17320decf4f26e6b4c942d046440d99bc23307059f48e2fc5792389bafc6cfa0594ff1382c671cc0f4e6ad5c312d83e964872a61
|
7
|
+
data.tar.gz: 2299ad7c8cdd56eddf50497351e2a654732aa72caca5d319cf6218185323a7cf9769113d0f62185ae7927acbbbeb4bec98b4963e5062590aadcc379b5581ec4a
|
@@ -0,0 +1,24 @@
|
|
1
|
+
---
|
2
|
+
name: Bug Report
|
3
|
+
about: Is Discard not working correctly for you? Let us know!
|
4
|
+
title: ''
|
5
|
+
labels: ''
|
6
|
+
assignees: ''
|
7
|
+
|
8
|
+
---
|
9
|
+
|
10
|
+
**Describe the bug**
|
11
|
+
A clear and concise description of what the bug is.
|
12
|
+
|
13
|
+
**To Reproduce**
|
14
|
+
Steps to reproduce the behavior:
|
15
|
+
1. Go to '...'
|
16
|
+
2. Click on '....'
|
17
|
+
3. Scroll down to '....'
|
18
|
+
4. See error
|
19
|
+
|
20
|
+
**Expected behavior**
|
21
|
+
A clear and concise description of what you expected to happen.
|
22
|
+
|
23
|
+
**Additional context**
|
24
|
+
Please tells us your Rails and Ruby versions, and anything else that might be helpful about the environment you encountered the issue.
|
@@ -0,0 +1,10 @@
|
|
1
|
+
---
|
2
|
+
name: Feature Proposal
|
3
|
+
about: Discard is feature-complete, but we're happy to hear you out!
|
4
|
+
title: ''
|
5
|
+
labels: ''
|
6
|
+
assignees: ''
|
7
|
+
|
8
|
+
---
|
9
|
+
|
10
|
+
**Discard is feature-complete, but if you have an idea for a feature that will benefit all discard users and that won't offer a significant maintenance burden, we're happy to listen. Explain it as best you can and we'll let you know if it's something we'd like to have or if it's something that might be a better off as an extension or fork.**
|
@@ -0,0 +1,30 @@
|
|
1
|
+
name: Test
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- master
|
7
|
+
pull_request:
|
8
|
+
branches:
|
9
|
+
- master
|
10
|
+
|
11
|
+
jobs:
|
12
|
+
build:
|
13
|
+
runs-on: ubuntu-latest
|
14
|
+
name: Test on Rails ${{ matrix.rails_version }}
|
15
|
+
strategy:
|
16
|
+
matrix:
|
17
|
+
rails_version:
|
18
|
+
- ~> 5.1.0
|
19
|
+
- ~> 5.2.0
|
20
|
+
- ~> 6.0.0
|
21
|
+
container: docker://ruby
|
22
|
+
steps:
|
23
|
+
- uses: actions/checkout@v1
|
24
|
+
- name: Build and test
|
25
|
+
run: |
|
26
|
+
gem install bundler
|
27
|
+
bundle install --jobs 4 --retry 3
|
28
|
+
bundle exec rake
|
29
|
+
env:
|
30
|
+
RAILS_VERSION: ${{ matrix.rails_version }}
|
data/.travis.yml
CHANGED
@@ -1,24 +1,28 @@
|
|
1
|
-
sudo: false
|
2
1
|
language: ruby
|
2
|
+
cache: bundler
|
3
3
|
rvm:
|
4
|
-
- 2.2
|
5
|
-
- 2.3
|
6
|
-
- 2.4
|
7
|
-
- 2.5
|
8
|
-
- 2.6
|
4
|
+
- 2.2
|
5
|
+
- 2.3
|
6
|
+
- 2.4
|
7
|
+
- 2.5
|
8
|
+
- 2.6
|
9
|
+
- 2.7
|
9
10
|
env:
|
10
11
|
matrix:
|
11
12
|
- RAILS_VERSION='~> 4.2.0' SQLITE_VERSION='~> 1.3.6'
|
12
13
|
- RAILS_VERSION='~> 5.0.0' SQLITE_VERSION='~> 1.3.6'
|
13
14
|
- RAILS_VERSION='~> 5.1.0'
|
14
|
-
- RAILS_VERSION='~> 5.2.
|
15
|
-
- RAILS_VERSION='~> 6.0.0
|
15
|
+
- RAILS_VERSION='~> 5.2.0'
|
16
|
+
- RAILS_VERSION='~> 6.0.0'
|
16
17
|
|
17
18
|
matrix:
|
18
19
|
exclude:
|
19
|
-
- rvm: 2.2
|
20
|
-
env: RAILS_VERSION='~> 6.0.0
|
21
|
-
- rvm: 2.3
|
22
|
-
env: RAILS_VERSION='~> 6.0.0
|
23
|
-
- rvm: 2.4
|
24
|
-
env: RAILS_VERSION='~> 6.0.0
|
20
|
+
- rvm: 2.2
|
21
|
+
env: RAILS_VERSION='~> 6.0.0'
|
22
|
+
- rvm: 2.3
|
23
|
+
env: RAILS_VERSION='~> 6.0.0'
|
24
|
+
- rvm: 2.4
|
25
|
+
env: RAILS_VERSION='~> 6.0.0'
|
26
|
+
# Rails 4.2 uses BigDecimal.new, which Ruby 2.7 removed
|
27
|
+
- rvm: 2.7
|
28
|
+
env: RAILS_VERSION='~> 4.2.0' SQLITE_VERSION='~> 1.3.6'
|
data/CHANGELOG.md
CHANGED
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.
|
16
|
+
gem 'discard', '~> 1.2'
|
17
17
|
```
|
18
18
|
|
19
19
|
And then execute:
|
@@ -57,7 +57,10 @@ Post.discarded # => []
|
|
57
57
|
|
58
58
|
post = Post.first # => #<Post id: 1, ...>
|
59
59
|
post.discard # => true
|
60
|
+
post.discard! # => Discard::RecordNotDiscarded: Failed to discard the record
|
60
61
|
post.discarded? # => true
|
62
|
+
post.undiscarded? # => false
|
63
|
+
post.kept? # => false
|
61
64
|
post.discarded_at # => 2017-04-18 18:49:49 -0700
|
62
65
|
|
63
66
|
Post.all # => [#<Post id: 1, ...>]
|
@@ -82,6 +85,8 @@ end
|
|
82
85
|
```ruby
|
83
86
|
post = Post.first # => #<Post id: 1, ...>
|
84
87
|
post.undiscard # => true
|
88
|
+
post.undiscard! # => Discard::RecordNotUndiscarded: Failed to undiscard the record
|
89
|
+
post.discarded_at # => nil
|
85
90
|
```
|
86
91
|
|
87
92
|
***From a controller***
|
@@ -123,6 +128,10 @@ class Comment < ActiveRecord::Base
|
|
123
128
|
|
124
129
|
include Discard::Model
|
125
130
|
scope :kept, -> { undiscarded.joins(:post).merge(Post.kept) }
|
131
|
+
|
132
|
+
def kept?
|
133
|
+
undiscarded? && post.kept?
|
134
|
+
end
|
126
135
|
end
|
127
136
|
|
128
137
|
Comment.kept
|
@@ -220,6 +229,12 @@ end
|
|
220
229
|
* Recursive discards (like AR's dependent: destroy) - This can be avoided using queries (See "Working with associations") or emulated using callbacks.
|
221
230
|
* Recursive restores - This concept is fundamentally broken, but not necessary if the recursive discards are avoided.
|
222
231
|
|
232
|
+
## Extensions
|
233
|
+
|
234
|
+
Discard provides the smallest subset of soft-deletion features that we think are useful to all users of the gem. We welcome the addition of gems that work with Discard to provide additional features.
|
235
|
+
|
236
|
+
- [discard-rails-observers](https://github.com/pelargir/discard-rails-observers) integrates discard with the [rails-observers gem](https://github.com/rails/rails-observers)
|
237
|
+
|
223
238
|
## Why not paranoia or acts_as_paranoid?
|
224
239
|
|
225
240
|
I've worked with and have helped maintain
|
@@ -256,7 +271,11 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|
256
271
|
|
257
272
|
## Contributing
|
258
273
|
|
259
|
-
|
274
|
+
Please consider filing an issue with the details of any features you'd like to see before implementing them. Discard is feature-complete and we are only interested in adding additional features that won't require substantial maintenance burden and that will benefit all users of the gem. We encourage anyone that needs additional or different behaviour to either create their own gem that builds off of discard or implement a new package with the different behaviour.
|
275
|
+
|
276
|
+
Discard is very simple and we like it that way. Creating your own clone or fork with slightly different behaviour may not be that much work!
|
277
|
+
|
278
|
+
If you find a bug in discard, please report it! We try to keep up with any issues and keep the gem running smoothly for everyone! You can report issues [here](https://github.com/jhawthorn/discard/issues).
|
260
279
|
|
261
280
|
## License
|
262
281
|
|
data/lib/discard/model.rb
CHANGED
@@ -43,6 +43,25 @@ module Discard
|
|
43
43
|
kept.each(&:discard)
|
44
44
|
end
|
45
45
|
|
46
|
+
# Discards the records by instantiating each
|
47
|
+
# record and calling its {#discard!} method.
|
48
|
+
# Each object's callbacks are executed.
|
49
|
+
# Returns the collection of objects that were discarded.
|
50
|
+
#
|
51
|
+
# Note: Instantiation, callback execution, and update of each
|
52
|
+
# record can be time consuming when you're discarding many records at
|
53
|
+
# once. It generates at least one SQL +UPDATE+ query per record (or
|
54
|
+
# possibly more, to enforce your callbacks). If you want to discard many
|
55
|
+
# rows quickly, without concern for their associations or callbacks, use
|
56
|
+
# #update_all!(discarded_at: Time.current) instead.
|
57
|
+
#
|
58
|
+
# ==== Examples
|
59
|
+
#
|
60
|
+
# Person.where(age: 0..18).discard_all!
|
61
|
+
def discard_all!
|
62
|
+
kept.each(&:discard!)
|
63
|
+
end
|
64
|
+
|
46
65
|
# Undiscards the records by instantiating each
|
47
66
|
# record and calling its {#undiscard} method.
|
48
67
|
# Each object's callbacks are executed.
|
@@ -61,6 +80,25 @@ module Discard
|
|
61
80
|
def undiscard_all
|
62
81
|
discarded.each(&:undiscard)
|
63
82
|
end
|
83
|
+
|
84
|
+
# Undiscards the records by instantiating each
|
85
|
+
# record and calling its {#undiscard!} method.
|
86
|
+
# Each object's callbacks are executed.
|
87
|
+
# Returns the collection of objects that were undiscarded.
|
88
|
+
#
|
89
|
+
# Note: Instantiation, callback execution, and update of each
|
90
|
+
# record can be time consuming when you're undiscarding many records at
|
91
|
+
# once. It generates at least one SQL +UPDATE+ query per record (or
|
92
|
+
# possibly more, to enforce your callbacks). If you want to undiscard many
|
93
|
+
# rows quickly, without concern for their associations or callbacks, use
|
94
|
+
# #update_all!(discarded_at: nil) instead.
|
95
|
+
#
|
96
|
+
# ==== Examples
|
97
|
+
#
|
98
|
+
# Person.where(age: 0..18).undiscard_all!
|
99
|
+
def undiscard_all!
|
100
|
+
discarded.each(&:undiscard!)
|
101
|
+
end
|
64
102
|
end
|
65
103
|
|
66
104
|
# @return [Boolean] true if this record has been discarded, otherwise false
|
@@ -68,11 +106,17 @@ module Discard
|
|
68
106
|
self[self.class.discard_column].present?
|
69
107
|
end
|
70
108
|
|
109
|
+
# @return [Boolean] false if this record has been discarded, otherwise true
|
110
|
+
def undiscarded?
|
111
|
+
!discarded?
|
112
|
+
end
|
113
|
+
alias kept? undiscarded?
|
114
|
+
|
71
115
|
# Discard the record in the database
|
72
116
|
#
|
73
117
|
# @return [Boolean] true if successful, otherwise false
|
74
118
|
def discard
|
75
|
-
return if discarded?
|
119
|
+
return false if discarded?
|
76
120
|
run_callbacks(:discard) do
|
77
121
|
update_attribute(self.class.discard_column, Time.current)
|
78
122
|
end
|
data/lib/discard/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: discard
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Hawthorn
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -122,6 +122,9 @@ executables: []
|
|
122
122
|
extensions: []
|
123
123
|
extra_rdoc_files: []
|
124
124
|
files:
|
125
|
+
- ".github/ISSUE_TEMPLATE/bug-report.md"
|
126
|
+
- ".github/ISSUE_TEMPLATE/feature-proposal.md"
|
127
|
+
- ".github/workflows/test.yml"
|
125
128
|
- ".gitignore"
|
126
129
|
- ".rspec"
|
127
130
|
- ".travis.yml"
|
@@ -158,7 +161,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
158
161
|
- !ruby/object:Gem::Version
|
159
162
|
version: '0'
|
160
163
|
requirements: []
|
161
|
-
rubygems_version: 3.0.
|
164
|
+
rubygems_version: 3.1.0.pre2
|
162
165
|
signing_key:
|
163
166
|
specification_version: 4
|
164
167
|
summary: ActiveRecord soft-deletes done right
|