acts_as_removable 1.1.0 → 3.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +24 -0
- data/.travis.yml +26 -5
- data/Changelog.md +24 -0
- data/Gemfile +2 -0
- data/LICENSE +1 -1
- data/README.md +0 -7
- data/Rakefile +4 -2
- data/acts_as_removable.gemspec +18 -14
- data/gemfiles/rails52 +7 -0
- data/gemfiles/rails60 +7 -0
- data/gemfiles/rails61 +7 -0
- data/lib/acts_as_removable.rb +15 -24
- data/lib/acts_as_removable/version.rb +3 -1
- data/spec/acts_as_removable_spec.rb +7 -5
- data/spec/spec_helper.rb +2 -0
- metadata +65 -22
- data/.ruby-version +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 40034410cd08fcf4834c5887a8f376acc3a014eed7e2d3d97337f96008c72084
|
4
|
+
data.tar.gz: 1374f4b5cd4da3d0acb5127cdeed92993bfe726e383ffc7f99fef1bc6b4a6634
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8836c4e7faeb99e54f04c6d021b9d06848557d73b9f7d61c3a5cf6e069a771867a4c29b753bea462fbd16c0094000df48dcc2ccd0757f3b5beb50abacddae38
|
7
|
+
data.tar.gz: e615ea16131b0e0584366a89c23a644b2066068cf4d49fdd0c32685ee3a0b3ae5da13d2b318ad7dcee1c49e79ed7ebcc3ffef2950ac9edd90c205073b1ccb7de
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-performance
|
3
|
+
|
4
|
+
AllCops:
|
5
|
+
TargetRubyVersion: 2.4
|
6
|
+
|
7
|
+
Layout/AlignHash:
|
8
|
+
EnforcedHashRocketStyle: table
|
9
|
+
EnforcedColonStyle: table
|
10
|
+
|
11
|
+
Metrics/LineLength:
|
12
|
+
Max: 120
|
13
|
+
|
14
|
+
Metrics/AbcSize:
|
15
|
+
Enabled: false
|
16
|
+
|
17
|
+
Metrics/MethodLength:
|
18
|
+
Enabled: false
|
19
|
+
|
20
|
+
Metrics/BlockLength:
|
21
|
+
Enabled: false
|
22
|
+
|
23
|
+
Style/Documentation:
|
24
|
+
Enabled: false
|
data/.travis.yml
CHANGED
@@ -1,7 +1,28 @@
|
|
1
|
+
sudo: false
|
2
|
+
|
1
3
|
language: ruby
|
4
|
+
|
2
5
|
rvm:
|
3
|
-
-
|
4
|
-
- 2.
|
5
|
-
- 2.
|
6
|
-
-
|
7
|
-
|
6
|
+
- 2.5.8
|
7
|
+
- 2.6.6
|
8
|
+
- 2.7.2
|
9
|
+
- 3.0.0
|
10
|
+
|
11
|
+
gemfile:
|
12
|
+
- gemfiles/rails52
|
13
|
+
- gemfiles/rails60
|
14
|
+
- gemfiles/rails61
|
15
|
+
|
16
|
+
matrix:
|
17
|
+
exclude:
|
18
|
+
- rvm: 2.5.8
|
19
|
+
gemfile: gemfiles/rails61
|
20
|
+
- rvm: 2.7.2
|
21
|
+
gemfile: gemfiles/rails52
|
22
|
+
- rvm: 3.0.0
|
23
|
+
gemfile: gemfiles/rails52
|
24
|
+
|
25
|
+
script: bundle exec rake spec
|
26
|
+
|
27
|
+
before_install:
|
28
|
+
- gem install bundler -v '~> 2.0'
|
data/Changelog.md
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
Changelog
|
2
|
+
===
|
3
|
+
|
4
|
+
#### Unreleased
|
5
|
+
|
6
|
+
#### 3.1.1 (2021-01-08)
|
7
|
+
* Add workaround for new argument handling in ruby 3
|
8
|
+
|
9
|
+
#### 3.1.0 (2020-12-10)
|
10
|
+
* Support for Rails 6.1.0
|
11
|
+
* Update travis config
|
12
|
+
* Reduce travis build matrix to save time and speed up CI
|
13
|
+
|
14
|
+
#### 3.0.1 (2019-11-06)
|
15
|
+
* Fix support for Rails 6.0.X patch level releases
|
16
|
+
|
17
|
+
#### 3.0.0 (2019-08-26)
|
18
|
+
* Support for Rails 6.0.0
|
19
|
+
* Drop support for Rails < 5.0.0
|
20
|
+
* Unpin bundler gem (development dependency)
|
21
|
+
* Cleanup gemspec
|
22
|
+
* Remove .ruby-version file
|
23
|
+
* Update copyright
|
24
|
+
* Add this Changelog
|
data/Gemfile
CHANGED
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -37,13 +37,6 @@ class MyModel < ActiveRecord::Base
|
|
37
37
|
end
|
38
38
|
```
|
39
39
|
|
40
|
-
It's possible to add a default scope with the active (not removed) records:
|
41
|
-
```ruby
|
42
|
-
class MyModel < ActiveRecord::Base
|
43
|
-
acts_as_removable with_default_scope: true
|
44
|
-
end
|
45
|
-
```
|
46
|
-
|
47
40
|
And you can use callbacks:
|
48
41
|
```ruby
|
49
42
|
class MyModel < ActiveRecord::Base
|
data/Rakefile
CHANGED
data/acts_as_removable.gemspec
CHANGED
@@ -1,28 +1,32 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'English'
|
4
6
|
require 'acts_as_removable/version'
|
5
7
|
|
6
8
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
9
|
+
spec.name = 'acts_as_removable'
|
8
10
|
spec.version = ActsAsRemovable::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
11
|
-
spec.description =
|
12
|
-
spec.summary =
|
13
|
-
spec.homepage =
|
14
|
-
spec.license =
|
11
|
+
spec.authors = ['Florian Schwab', 'Erik-B. Ernst']
|
12
|
+
spec.email = ['florian.schwab@sic.software', 'erik.ernst@sic.software']
|
13
|
+
spec.description = 'Simplifies handling of pseudo removed records.'
|
14
|
+
spec.summary = 'Simplifies handling of pseudo removed records.'
|
15
|
+
spec.homepage = 'https://github.com/SICSoftwareGmbH/acts_as_removable'
|
16
|
+
spec.license = 'MIT'
|
15
17
|
|
16
|
-
spec.files = `git ls-files`.split(
|
18
|
+
spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
17
19
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
20
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = [
|
21
|
+
spec.require_paths = ['lib']
|
20
22
|
|
21
|
-
spec.add_dependency '
|
22
|
-
spec.add_dependency '
|
23
|
+
spec.add_dependency 'activerecord', '>= 5.0', '< 6.2'
|
24
|
+
spec.add_dependency 'activesupport', '>= 5.0', '< 6.2'
|
23
25
|
|
24
|
-
spec.add_development_dependency 'bundler', '~>
|
26
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
25
27
|
spec.add_development_dependency 'rake'
|
26
28
|
spec.add_development_dependency 'rspec'
|
29
|
+
spec.add_development_dependency 'rubocop'
|
30
|
+
spec.add_development_dependency 'rubocop-performance'
|
27
31
|
spec.add_development_dependency 'sqlite3'
|
28
32
|
end
|
data/gemfiles/rails52
ADDED
data/gemfiles/rails60
ADDED
data/gemfiles/rails61
ADDED
data/lib/acts_as_removable.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'active_support/concern'
|
2
4
|
require 'active_record'
|
3
|
-
require
|
5
|
+
require 'acts_as_removable/version'
|
4
6
|
|
5
7
|
module ActsAsRemovable
|
6
8
|
extend ActiveSupport::Concern
|
@@ -10,29 +12,21 @@ module ActsAsRemovable
|
|
10
12
|
#
|
11
13
|
# acts_as_removable
|
12
14
|
# acts_as_removable column_name: 'other_column_name'
|
13
|
-
# acts_as_removable with_default_scope: true
|
14
15
|
#
|
15
16
|
# ===== Options
|
16
17
|
#
|
17
18
|
# * <tt>:column_name</tt> - A symbol or string with the column to use for removal timestamp.
|
18
|
-
# * <tt>:with_default_scope</tt> - A boolean indicating to set a default scope with only active (not removed) records
|
19
19
|
def acts_as_removable(options = {})
|
20
20
|
_acts_as_removable_options.merge!(options)
|
21
21
|
|
22
|
-
scope :removed,
|
23
|
-
|
24
|
-
query = where(all.table[removed_at_column_name].not_eq(nil).to_sql)
|
25
|
-
_removable_where_values(query, removed_at_column_name, all.table[removed_at_column_name].eq(nil).to_sql)
|
22
|
+
scope :removed, lambda {
|
23
|
+
where(all.table[_acts_as_removable_options[:column_name]].not_eq(nil).to_sql)
|
26
24
|
}
|
27
25
|
|
28
|
-
scope :actives,
|
29
|
-
|
30
|
-
query = where(all.table[removed_at_column_name].eq(nil).to_sql)
|
31
|
-
_removable_where_values(query, removed_at_column_name, all.table[removed_at_column_name].not_eq(nil).to_sql)
|
26
|
+
scope :actives, lambda {
|
27
|
+
where(all.table[_acts_as_removable_options[:column_name]].eq(nil).to_sql)
|
32
28
|
}
|
33
29
|
|
34
|
-
default_scope -> {where(all.table[_acts_as_removable_options[:column_name]].eq(nil).to_sql)} if _acts_as_removable_options[:with_default_scope]
|
35
|
-
|
36
30
|
define_model_callbacks :remove, :unremove
|
37
31
|
|
38
32
|
class_eval do
|
@@ -76,7 +70,13 @@ module ActsAsRemovable
|
|
76
70
|
self.class.transaction do
|
77
71
|
run_callbacks callback.to_sym do
|
78
72
|
send("#{self.class._acts_as_removable_options[:column_name]}=", value)
|
79
|
-
|
73
|
+
|
74
|
+
# workaround for new argument handling
|
75
|
+
if RUBY_VERSION.to_i < 3
|
76
|
+
with_bang ? save!(options) : save(options)
|
77
|
+
else
|
78
|
+
with_bang ? save!(**options) : save(**options)
|
79
|
+
end
|
80
80
|
end
|
81
81
|
end
|
82
82
|
end
|
@@ -84,16 +84,7 @@ module ActsAsRemovable
|
|
84
84
|
end
|
85
85
|
|
86
86
|
def _acts_as_removable_options
|
87
|
-
@_acts_as_removable_options ||= {
|
88
|
-
column_name: 'removed_at'
|
89
|
-
}
|
90
|
-
end
|
91
|
-
|
92
|
-
# Delete where statements from query
|
93
|
-
def _removable_where_values(query, column_name, remove_where)
|
94
|
-
query = query.with_default_scope if query.respond_to?(:with_default_scope)
|
95
|
-
query.where_values.delete(remove_where)
|
96
|
-
query
|
87
|
+
@_acts_as_removable_options ||= { column_name: 'removed_at' }
|
97
88
|
end
|
98
89
|
end
|
99
90
|
end
|
@@ -1,8 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe 'acts_as_removable' do
|
4
6
|
class MyModel < ActiveRecord::Base
|
5
|
-
acts_as_removable
|
7
|
+
acts_as_removable
|
6
8
|
attr_accessor :callback_before_remove, :callback_after_remove, :callback_before_unremove, :callback_after_unremove
|
7
9
|
before_remove do |r|
|
8
10
|
r.callback_before_remove = true
|
@@ -26,10 +28,10 @@ describe 'acts_as_removable' do
|
|
26
28
|
before do
|
27
29
|
# setup database
|
28
30
|
db_file = File.expand_path(File.join(File.dirname(__FILE__), '..', 'tmp', 'acts_as_removable.db'))
|
29
|
-
Dir
|
31
|
+
Dir.mkdir(File.dirname(db_file)) unless File.exist?(File.dirname(db_file))
|
30
32
|
ActiveRecord::Base.establish_connection(
|
31
|
-
:
|
32
|
-
:
|
33
|
+
adapter: 'sqlite3',
|
34
|
+
database: "#{File.expand_path(File.join(File.dirname(__FILE__), '..'))}/tmp/acts_as_removable.db"
|
33
35
|
)
|
34
36
|
ActiveRecord::Base.connection.execute("DROP TABLE IF EXISTS 'my_models'")
|
35
37
|
ActiveRecord::Base.connection.create_table(:my_models) do |t|
|
@@ -62,7 +64,7 @@ describe 'acts_as_removable' do
|
|
62
64
|
MySecondModel.create!
|
63
65
|
MySecondModel.create!.remove!
|
64
66
|
|
65
|
-
expect(MyModel.count).to be(
|
67
|
+
expect(MyModel.count).to be(2)
|
66
68
|
expect(MyModel.actives.count).to be(1)
|
67
69
|
expect(MyModel.removed.count).to be(1)
|
68
70
|
expect(MyModel.unscoped.count).to be(2)
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,58 +1,70 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_removable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1
|
4
|
+
version: 3.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Florian Schwab
|
8
|
-
- Erik Ernst
|
8
|
+
- Erik-B. Ernst
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2021-01-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
15
|
+
name: activerecord
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- - "
|
18
|
+
- - ">="
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version:
|
20
|
+
version: '5.0'
|
21
|
+
- - "<"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: '6.2'
|
21
24
|
type: :runtime
|
22
25
|
prerelease: false
|
23
26
|
version_requirements: !ruby/object:Gem::Requirement
|
24
27
|
requirements:
|
25
|
-
- - "
|
28
|
+
- - ">="
|
26
29
|
- !ruby/object:Gem::Version
|
27
|
-
version:
|
30
|
+
version: '5.0'
|
31
|
+
- - "<"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '6.2'
|
28
34
|
- !ruby/object:Gem::Dependency
|
29
|
-
name:
|
35
|
+
name: activesupport
|
30
36
|
requirement: !ruby/object:Gem::Requirement
|
31
37
|
requirements:
|
32
|
-
- - "
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5.0'
|
41
|
+
- - "<"
|
33
42
|
- !ruby/object:Gem::Version
|
34
|
-
version:
|
43
|
+
version: '6.2'
|
35
44
|
type: :runtime
|
36
45
|
prerelease: false
|
37
46
|
version_requirements: !ruby/object:Gem::Requirement
|
38
47
|
requirements:
|
39
|
-
- - "
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '5.0'
|
51
|
+
- - "<"
|
40
52
|
- !ruby/object:Gem::Version
|
41
|
-
version:
|
53
|
+
version: '6.2'
|
42
54
|
- !ruby/object:Gem::Dependency
|
43
55
|
name: bundler
|
44
56
|
requirement: !ruby/object:Gem::Requirement
|
45
57
|
requirements:
|
46
58
|
- - "~>"
|
47
59
|
- !ruby/object:Gem::Version
|
48
|
-
version: '
|
60
|
+
version: '2.0'
|
49
61
|
type: :development
|
50
62
|
prerelease: false
|
51
63
|
version_requirements: !ruby/object:Gem::Requirement
|
52
64
|
requirements:
|
53
65
|
- - "~>"
|
54
66
|
- !ruby/object:Gem::Version
|
55
|
-
version: '
|
67
|
+
version: '2.0'
|
56
68
|
- !ruby/object:Gem::Dependency
|
57
69
|
name: rake
|
58
70
|
requirement: !ruby/object:Gem::Requirement
|
@@ -81,6 +93,34 @@ dependencies:
|
|
81
93
|
- - ">="
|
82
94
|
- !ruby/object:Gem::Version
|
83
95
|
version: '0'
|
96
|
+
- !ruby/object:Gem::Dependency
|
97
|
+
name: rubocop
|
98
|
+
requirement: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
type: :development
|
104
|
+
prerelease: false
|
105
|
+
version_requirements: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: rubocop-performance
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
type: :development
|
118
|
+
prerelease: false
|
119
|
+
version_requirements: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
84
124
|
- !ruby/object:Gem::Dependency
|
85
125
|
name: sqlite3
|
86
126
|
requirement: !ruby/object:Gem::Requirement
|
@@ -95,21 +135,26 @@ dependencies:
|
|
95
135
|
- - ">="
|
96
136
|
- !ruby/object:Gem::Version
|
97
137
|
version: '0'
|
98
|
-
description: Simplifies handling of pseudo removed records
|
138
|
+
description: Simplifies handling of pseudo removed records.
|
99
139
|
email:
|
100
|
-
- florian.schwab@sic
|
140
|
+
- florian.schwab@sic.software
|
141
|
+
- erik.ernst@sic.software
|
101
142
|
executables: []
|
102
143
|
extensions: []
|
103
144
|
extra_rdoc_files: []
|
104
145
|
files:
|
105
146
|
- ".gitignore"
|
106
|
-
- ".
|
147
|
+
- ".rubocop.yml"
|
107
148
|
- ".travis.yml"
|
149
|
+
- Changelog.md
|
108
150
|
- Gemfile
|
109
151
|
- LICENSE
|
110
152
|
- README.md
|
111
153
|
- Rakefile
|
112
154
|
- acts_as_removable.gemspec
|
155
|
+
- gemfiles/rails52
|
156
|
+
- gemfiles/rails60
|
157
|
+
- gemfiles/rails61
|
113
158
|
- lib/acts_as_removable.rb
|
114
159
|
- lib/acts_as_removable/version.rb
|
115
160
|
- spec/acts_as_removable_spec.rb
|
@@ -133,12 +178,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
133
178
|
- !ruby/object:Gem::Version
|
134
179
|
version: '0'
|
135
180
|
requirements: []
|
136
|
-
|
137
|
-
rubygems_version: 2.4.6
|
181
|
+
rubygems_version: 3.2.3
|
138
182
|
signing_key:
|
139
183
|
specification_version: 4
|
140
|
-
summary: Simplifies handling of pseudo removed records
|
184
|
+
summary: Simplifies handling of pseudo removed records.
|
141
185
|
test_files:
|
142
186
|
- spec/acts_as_removable_spec.rb
|
143
187
|
- spec/spec_helper.rb
|
144
|
-
has_rdoc:
|
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
ruby-2.0.0
|