lite-archive 1.1.3 → 1.2.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 +4 -4
- data/.rubocop.yml +3 -2
- data/CHANGELOG.md +6 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +78 -76
- data/README.md +33 -29
- data/Rakefile +2 -2
- data/bin/console +3 -3
- data/lib/generators/lite/archive/install_generator.rb +2 -2
- data/lib/lite/archive/base.rb +17 -12
- data/lib/lite/archive/methods.rb +1 -1
- data/lib/lite/archive/railtie.rb +1 -1
- data/lib/lite/archive/version.rb +1 -1
- data/lib/lite/archive.rb +11 -11
- data/lite-archive.gemspec +28 -34
- metadata +9 -5
- data/.travis.yml +0 -25
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ce473b0e1ae99d9aa1538d656d8fe2cbff4a4e87a061133eccdeed2071da3c77
|
|
4
|
+
data.tar.gz: cbab98bf4a3d868e7f3df0f95eb85b5306f4b5ab2acbb1d4a1524640340fdd8d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9367ccb1e70e77c172d7742f846d63ee2a36bbc9be9966249faeaa0fa20504c55efd28e1bddda53a4d922af22a9575d9278b0bcb048b38cf20efb6b4a8ac49b4
|
|
7
|
+
data.tar.gz: 2a16b5bcea3da1f7c859c6b79ad69595fba681979168d2a09a3016267f380f67c6840a80ad8a8c1c08c4c8ed31a37736d0905ef6e4efb58b57ed462783394560
|
data/.rubocop.yml
CHANGED
|
@@ -3,7 +3,6 @@ require:
|
|
|
3
3
|
- rubocop-rake
|
|
4
4
|
- rubocop-rspec
|
|
5
5
|
AllCops:
|
|
6
|
-
TargetRubyVersion: 3.0
|
|
7
6
|
NewCops: enable
|
|
8
7
|
DisplayCopNames: true
|
|
9
8
|
DisplayStyleGuide: true
|
|
@@ -19,7 +18,7 @@ Layout/EmptyLinesAroundClassBody:
|
|
|
19
18
|
Layout/EmptyLinesAroundModuleBody:
|
|
20
19
|
EnforcedStyle: empty_lines_except_namespace
|
|
21
20
|
Layout/LineLength:
|
|
22
|
-
|
|
21
|
+
Enabled: false
|
|
23
22
|
Layout/SpaceAroundMethodCallOperator:
|
|
24
23
|
Enabled: true
|
|
25
24
|
Lint/RaiseException:
|
|
@@ -38,3 +37,5 @@ Style/Documentation:
|
|
|
38
37
|
Enabled: false
|
|
39
38
|
Style/ExpandPathArguments:
|
|
40
39
|
Enabled: false
|
|
40
|
+
Style/StringLiterals:
|
|
41
|
+
EnforcedStyle: double_quotes
|
data/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [1.2.0] - 2022-11-19
|
|
10
|
+
### Changed
|
|
11
|
+
- Improved docs
|
|
12
|
+
- Improve internal setup
|
|
13
|
+
- Improved rubocop setup
|
|
14
|
+
|
|
9
15
|
## [1.1.3] - 2021-07-22
|
|
10
16
|
### Changed
|
|
11
17
|
- Move locales to lib
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,41 +1,40 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
lite-archive (1.
|
|
4
|
+
lite-archive (1.2.0)
|
|
5
5
|
activerecord
|
|
6
6
|
activesupport
|
|
7
7
|
|
|
8
8
|
GEM
|
|
9
9
|
remote: https://rubygems.org/
|
|
10
10
|
specs:
|
|
11
|
-
actionpack (
|
|
12
|
-
actionview (=
|
|
13
|
-
activesupport (=
|
|
14
|
-
rack (~> 2.0, >= 2.0
|
|
11
|
+
actionpack (7.0.4)
|
|
12
|
+
actionview (= 7.0.4)
|
|
13
|
+
activesupport (= 7.0.4)
|
|
14
|
+
rack (~> 2.0, >= 2.2.0)
|
|
15
15
|
rack-test (>= 0.6.3)
|
|
16
16
|
rails-dom-testing (~> 2.0)
|
|
17
17
|
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
|
18
|
-
actionview (
|
|
19
|
-
activesupport (=
|
|
18
|
+
actionview (7.0.4)
|
|
19
|
+
activesupport (= 7.0.4)
|
|
20
20
|
builder (~> 3.1)
|
|
21
21
|
erubi (~> 1.4)
|
|
22
22
|
rails-dom-testing (~> 2.0)
|
|
23
23
|
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
|
24
|
-
activemodel (
|
|
25
|
-
activesupport (=
|
|
26
|
-
activerecord (
|
|
27
|
-
activemodel (=
|
|
28
|
-
activesupport (=
|
|
29
|
-
activesupport (
|
|
24
|
+
activemodel (7.0.4)
|
|
25
|
+
activesupport (= 7.0.4)
|
|
26
|
+
activerecord (7.0.4)
|
|
27
|
+
activemodel (= 7.0.4)
|
|
28
|
+
activesupport (= 7.0.4)
|
|
29
|
+
activesupport (7.0.4)
|
|
30
30
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
31
31
|
i18n (>= 1.6, < 2)
|
|
32
32
|
minitest (>= 5.1)
|
|
33
33
|
tzinfo (~> 2.0)
|
|
34
|
-
zeitwerk (~> 2.3)
|
|
35
34
|
ast (2.4.2)
|
|
36
35
|
builder (3.2.4)
|
|
37
36
|
colorize (0.8.1)
|
|
38
|
-
concurrent-ruby (1.1.
|
|
37
|
+
concurrent-ruby (1.1.10)
|
|
39
38
|
crass (1.0.6)
|
|
40
39
|
database_cleaner (2.0.1)
|
|
41
40
|
database_cleaner-active_record (~> 2.0.0)
|
|
@@ -43,97 +42,100 @@ GEM
|
|
|
43
42
|
activerecord (>= 5.a)
|
|
44
43
|
database_cleaner-core (~> 2.0.0)
|
|
45
44
|
database_cleaner-core (2.0.1)
|
|
46
|
-
diff-lcs (1.
|
|
47
|
-
erubi (1.
|
|
48
|
-
fasterer (0.
|
|
45
|
+
diff-lcs (1.5.0)
|
|
46
|
+
erubi (1.11.0)
|
|
47
|
+
fasterer (0.10.0)
|
|
49
48
|
colorize (~> 0.7)
|
|
50
|
-
ruby_parser (>= 3.
|
|
49
|
+
ruby_parser (>= 3.19.1)
|
|
51
50
|
generator_spec (0.9.4)
|
|
52
51
|
activesupport (>= 3.0.0)
|
|
53
52
|
railties (>= 3.0.0)
|
|
54
|
-
i18n (1.
|
|
53
|
+
i18n (1.12.0)
|
|
55
54
|
concurrent-ruby (~> 1.0)
|
|
56
|
-
|
|
55
|
+
json (2.6.2)
|
|
56
|
+
loofah (2.19.0)
|
|
57
57
|
crass (~> 1.0.2)
|
|
58
58
|
nokogiri (>= 1.5.9)
|
|
59
59
|
method_source (1.0.0)
|
|
60
|
-
mini_portile2 (2.
|
|
61
|
-
minitest (5.
|
|
62
|
-
nokogiri (1.
|
|
63
|
-
mini_portile2 (~> 2.
|
|
60
|
+
mini_portile2 (2.8.0)
|
|
61
|
+
minitest (5.16.3)
|
|
62
|
+
nokogiri (1.13.9)
|
|
63
|
+
mini_portile2 (~> 2.8.0)
|
|
64
64
|
racc (~> 1.4)
|
|
65
|
-
parallel (1.
|
|
66
|
-
parser (3.
|
|
65
|
+
parallel (1.22.1)
|
|
66
|
+
parser (3.1.2.1)
|
|
67
67
|
ast (~> 2.4.1)
|
|
68
|
-
racc (1.
|
|
69
|
-
rack (2.2.
|
|
70
|
-
rack-test (
|
|
71
|
-
rack (>= 1.
|
|
68
|
+
racc (1.6.0)
|
|
69
|
+
rack (2.2.4)
|
|
70
|
+
rack-test (2.0.2)
|
|
71
|
+
rack (>= 1.3)
|
|
72
72
|
rails-dom-testing (2.0.3)
|
|
73
73
|
activesupport (>= 4.2.0)
|
|
74
74
|
nokogiri (>= 1.6)
|
|
75
|
-
rails-html-sanitizer (1.3
|
|
75
|
+
rails-html-sanitizer (1.4.3)
|
|
76
76
|
loofah (~> 2.3)
|
|
77
|
-
railties (
|
|
78
|
-
actionpack (=
|
|
79
|
-
activesupport (=
|
|
77
|
+
railties (7.0.4)
|
|
78
|
+
actionpack (= 7.0.4)
|
|
79
|
+
activesupport (= 7.0.4)
|
|
80
80
|
method_source
|
|
81
|
-
rake (>=
|
|
81
|
+
rake (>= 12.2)
|
|
82
82
|
thor (~> 1.0)
|
|
83
|
-
|
|
83
|
+
zeitwerk (~> 2.5)
|
|
84
|
+
rainbow (3.1.1)
|
|
84
85
|
rake (13.0.6)
|
|
85
|
-
regexp_parser (2.
|
|
86
|
+
regexp_parser (2.6.1)
|
|
86
87
|
rexml (3.2.5)
|
|
87
|
-
rspec (3.
|
|
88
|
-
rspec-core (~> 3.
|
|
89
|
-
rspec-expectations (~> 3.
|
|
90
|
-
rspec-mocks (~> 3.
|
|
91
|
-
rspec-core (3.
|
|
92
|
-
rspec-support (~> 3.
|
|
93
|
-
rspec-expectations (3.
|
|
88
|
+
rspec (3.12.0)
|
|
89
|
+
rspec-core (~> 3.12.0)
|
|
90
|
+
rspec-expectations (~> 3.12.0)
|
|
91
|
+
rspec-mocks (~> 3.12.0)
|
|
92
|
+
rspec-core (3.12.0)
|
|
93
|
+
rspec-support (~> 3.12.0)
|
|
94
|
+
rspec-expectations (3.12.0)
|
|
94
95
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
95
|
-
rspec-support (~> 3.
|
|
96
|
-
rspec-mocks (3.
|
|
96
|
+
rspec-support (~> 3.12.0)
|
|
97
|
+
rspec-mocks (3.12.0)
|
|
97
98
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
98
|
-
rspec-support (~> 3.
|
|
99
|
-
rspec-rails (
|
|
100
|
-
actionpack (>=
|
|
101
|
-
activesupport (>=
|
|
102
|
-
railties (>=
|
|
103
|
-
rspec-core (~> 3.
|
|
104
|
-
rspec-expectations (~> 3.
|
|
105
|
-
rspec-mocks (~> 3.
|
|
106
|
-
rspec-support (~> 3.
|
|
107
|
-
rspec-support (3.
|
|
108
|
-
rubocop (1.
|
|
99
|
+
rspec-support (~> 3.12.0)
|
|
100
|
+
rspec-rails (6.0.1)
|
|
101
|
+
actionpack (>= 6.1)
|
|
102
|
+
activesupport (>= 6.1)
|
|
103
|
+
railties (>= 6.1)
|
|
104
|
+
rspec-core (~> 3.11)
|
|
105
|
+
rspec-expectations (~> 3.11)
|
|
106
|
+
rspec-mocks (~> 3.11)
|
|
107
|
+
rspec-support (~> 3.11)
|
|
108
|
+
rspec-support (3.12.0)
|
|
109
|
+
rubocop (1.39.0)
|
|
110
|
+
json (~> 2.3)
|
|
109
111
|
parallel (~> 1.10)
|
|
110
|
-
parser (>= 3.
|
|
112
|
+
parser (>= 3.1.2.1)
|
|
111
113
|
rainbow (>= 2.2.2, < 4.0)
|
|
112
114
|
regexp_parser (>= 1.8, < 3.0)
|
|
113
|
-
rexml
|
|
114
|
-
rubocop-ast (>= 1.
|
|
115
|
+
rexml (>= 3.2.5, < 4.0)
|
|
116
|
+
rubocop-ast (>= 1.23.0, < 2.0)
|
|
115
117
|
ruby-progressbar (~> 1.7)
|
|
116
118
|
unicode-display_width (>= 1.4.0, < 3.0)
|
|
117
|
-
rubocop-ast (1.
|
|
118
|
-
parser (>= 3.
|
|
119
|
-
rubocop-performance (1.
|
|
119
|
+
rubocop-ast (1.23.0)
|
|
120
|
+
parser (>= 3.1.1.0)
|
|
121
|
+
rubocop-performance (1.15.1)
|
|
120
122
|
rubocop (>= 1.7.0, < 2.0)
|
|
121
123
|
rubocop-ast (>= 0.4.0)
|
|
122
124
|
rubocop-rake (0.6.0)
|
|
123
125
|
rubocop (~> 1.0)
|
|
124
|
-
rubocop-rspec (2.
|
|
125
|
-
rubocop (~> 1.
|
|
126
|
-
rubocop-ast (>= 1.1.0)
|
|
126
|
+
rubocop-rspec (2.15.0)
|
|
127
|
+
rubocop (~> 1.33)
|
|
127
128
|
ruby-progressbar (1.11.0)
|
|
128
|
-
ruby_parser (3.
|
|
129
|
-
sexp_processor (~> 4.
|
|
130
|
-
sexp_processor (4.
|
|
131
|
-
sqlite3 (1.4
|
|
132
|
-
|
|
133
|
-
|
|
129
|
+
ruby_parser (3.19.1)
|
|
130
|
+
sexp_processor (~> 4.16)
|
|
131
|
+
sexp_processor (4.16.1)
|
|
132
|
+
sqlite3 (1.5.4)
|
|
133
|
+
mini_portile2 (~> 2.8.0)
|
|
134
|
+
thor (1.2.1)
|
|
135
|
+
tzinfo (2.0.5)
|
|
134
136
|
concurrent-ruby (~> 1.0)
|
|
135
|
-
unicode-display_width (2.
|
|
136
|
-
zeitwerk (2.
|
|
137
|
+
unicode-display_width (2.3.0)
|
|
138
|
+
zeitwerk (2.6.6)
|
|
137
139
|
|
|
138
140
|
PLATFORMS
|
|
139
141
|
ruby
|
|
@@ -154,4 +156,4 @@ DEPENDENCIES
|
|
|
154
156
|
sqlite3
|
|
155
157
|
|
|
156
158
|
BUNDLED WITH
|
|
157
|
-
2.
|
|
159
|
+
2.3.26
|
data/README.md
CHANGED
|
@@ -5,8 +5,6 @@
|
|
|
5
5
|
|
|
6
6
|
Lite::Archive is a library for archiving (soft-delete) database records.
|
|
7
7
|
|
|
8
|
-
**NOTE:** If you are coming from `ActiveArchive`, please read the [port](#port) section.
|
|
9
|
-
|
|
10
8
|
## Installation
|
|
11
9
|
|
|
12
10
|
Add this line to your application's Gemfile:
|
|
@@ -30,12 +28,11 @@ Or install it yourself as:
|
|
|
30
28
|
* [Methods](#methods)
|
|
31
29
|
* [Scopes](#scopes)
|
|
32
30
|
* [Callbacks](#callbacks)
|
|
33
|
-
* [Port](#port)
|
|
34
31
|
|
|
35
32
|
## Configurations
|
|
36
33
|
|
|
37
|
-
`rails g lite:archive:install` will generate the following file:
|
|
38
|
-
|
|
34
|
+
`rails g lite:archive:install` will generate the following file in your application root:
|
|
35
|
+
`config/initalizers/lite_archive.rb`
|
|
39
36
|
|
|
40
37
|
```ruby
|
|
41
38
|
Lite::Archive.configure do |config|
|
|
@@ -46,35 +43,46 @@ end
|
|
|
46
43
|
|
|
47
44
|
## Usage
|
|
48
45
|
|
|
49
|
-
An `archived_at` column must be added to tables where you
|
|
50
|
-
If the table does not have this column, records will be
|
|
46
|
+
An `archived_at` column must be added to tables where you that you want to archive.
|
|
47
|
+
If the table does not have this column, records will be destroyed instead.
|
|
51
48
|
|
|
49
|
+
#### Table create
|
|
52
50
|
```ruby
|
|
53
51
|
class AddArchivedAtColumn < ActiveRecord::Migration
|
|
54
52
|
def change
|
|
55
53
|
create_table :table_name do |t|
|
|
56
|
-
t.timestamp # Adds archived_at automatically
|
|
54
|
+
t.timestamp # Adds archived_at automatically if all_records_archivable
|
|
57
55
|
t.timestamp archive: true # Adds archived_at timestamp
|
|
58
56
|
t.timestamp archive: false # Does NOT add archived_at timestamp
|
|
59
57
|
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
```
|
|
60
61
|
|
|
61
|
-
|
|
62
|
-
|
|
62
|
+
#### Column migration
|
|
63
|
+
```ruby
|
|
64
|
+
class AddArchivedAtColumn < ActiveRecord::Migration
|
|
65
|
+
def change
|
|
63
66
|
add_column :table_name, :archived_at, :datetime # Manual column (null constraint must be false)
|
|
67
|
+
add_timestamp :table_name # Named column helper (equivalent to the above)
|
|
64
68
|
end
|
|
65
69
|
end
|
|
66
70
|
```
|
|
67
71
|
|
|
68
72
|
## Methods
|
|
69
73
|
|
|
74
|
+
#### Instance
|
|
70
75
|
```ruby
|
|
71
76
|
user = User.first
|
|
72
|
-
user.archive
|
|
73
|
-
user.unarchive
|
|
74
|
-
user.to_archival
|
|
77
|
+
user.archive #=> Archives the User record and its dependents
|
|
78
|
+
user.unarchive #=> Unarchives the User record and its dependents
|
|
79
|
+
user.to_archival #=> Returns the User archival state locale string (ex: Archived)
|
|
80
|
+
```
|
|
75
81
|
|
|
76
|
-
|
|
77
|
-
|
|
82
|
+
#### Class
|
|
83
|
+
```ruby
|
|
84
|
+
User.archive_all #=> Archives all User records and their dependents
|
|
85
|
+
User.unarchive_all #=> Unarchives all User record and their dependents
|
|
78
86
|
```
|
|
79
87
|
|
|
80
88
|
## Scopes
|
|
@@ -86,25 +94,21 @@ User.unarchived.all #=> Returns only unarchived records
|
|
|
86
94
|
|
|
87
95
|
## Callbacks
|
|
88
96
|
|
|
97
|
+
#### Before
|
|
89
98
|
```ruby
|
|
90
99
|
class User < ActiveRecord::Base
|
|
91
|
-
# ... omitted ...
|
|
92
|
-
|
|
93
100
|
before_archive :do_something
|
|
94
|
-
after_archive :do_something
|
|
95
|
-
|
|
96
101
|
before_unarchived :do_something
|
|
97
|
-
after_unarchive :do_something
|
|
98
|
-
|
|
99
|
-
# ... omitted ...
|
|
100
102
|
end
|
|
101
103
|
```
|
|
102
104
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
105
|
+
#### After
|
|
106
|
+
```ruby
|
|
107
|
+
class User < ActiveRecord::Base
|
|
108
|
+
after_archive :do_something
|
|
109
|
+
after_unarchive :do_something
|
|
110
|
+
end
|
|
111
|
+
```
|
|
108
112
|
|
|
109
113
|
## Development
|
|
110
114
|
|
|
@@ -114,7 +118,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
|
114
118
|
|
|
115
119
|
## Contributing
|
|
116
120
|
|
|
117
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
|
121
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/drexed/lite-archive. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
|
118
122
|
|
|
119
123
|
## License
|
|
120
124
|
|
|
@@ -122,4 +126,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
|
122
126
|
|
|
123
127
|
## Code of Conduct
|
|
124
128
|
|
|
125
|
-
Everyone interacting in the Lite::Archive project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/
|
|
129
|
+
Everyone interacting in the Lite::Archive project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/drexed/lite-archive/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
|
-
require
|
|
5
|
-
require
|
|
4
|
+
require "bundler/setup"
|
|
5
|
+
require "lite/archive"
|
|
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.
|
|
@@ -11,5 +11,5 @@ require 'lite/archive'
|
|
|
11
11
|
# require "pry"
|
|
12
12
|
# Pry.start
|
|
13
13
|
|
|
14
|
-
require
|
|
14
|
+
require "irb"
|
|
15
15
|
IRB.start(__FILE__)
|
|
@@ -4,10 +4,10 @@ module Lite
|
|
|
4
4
|
module Archive
|
|
5
5
|
class InstallGenerator < Rails::Generators::Base
|
|
6
6
|
|
|
7
|
-
source_root File.expand_path(
|
|
7
|
+
source_root File.expand_path("../templates", __FILE__)
|
|
8
8
|
|
|
9
9
|
def copy_initializer_file
|
|
10
|
-
copy_file(
|
|
10
|
+
copy_file("install.rb", "config/initializers/lite_archive.rb")
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
end
|
data/lib/lite/archive/base.rb
CHANGED
|
@@ -9,7 +9,8 @@ module Lite
|
|
|
9
9
|
base.extend Scopes
|
|
10
10
|
|
|
11
11
|
base.instance_eval do
|
|
12
|
-
|
|
12
|
+
define_model_callbacks :archive, only: %i[before after]
|
|
13
|
+
define_model_callbacks :unarchive, only: %i[before after]
|
|
13
14
|
end
|
|
14
15
|
end
|
|
15
16
|
|
|
@@ -84,12 +85,14 @@ module Lite
|
|
|
84
85
|
|
|
85
86
|
self.updated_at = ts if updatable?
|
|
86
87
|
self.archived_at = ts
|
|
88
|
+
|
|
87
89
|
save(validate: false)
|
|
88
90
|
end
|
|
89
91
|
|
|
90
92
|
def mark_as_unarchived
|
|
91
93
|
self.updated_at = archival_timestamp if updatable?
|
|
92
94
|
self.archived_at = nil
|
|
95
|
+
|
|
93
96
|
save(validate: false)
|
|
94
97
|
end
|
|
95
98
|
|
|
@@ -101,12 +104,13 @@ module Lite
|
|
|
101
104
|
dependents = reflection_dependents(table_name)
|
|
102
105
|
next if dependents.nil?
|
|
103
106
|
|
|
104
|
-
action =
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
107
|
+
action =
|
|
108
|
+
case [reflection_marco(reflection), archivable?]
|
|
109
|
+
when ["one", true] then :archive
|
|
110
|
+
when ["one", false] then :destroy
|
|
111
|
+
when ["many", true] then :archive_all
|
|
112
|
+
when ["many", false] then :destroy_all
|
|
113
|
+
end
|
|
110
114
|
|
|
111
115
|
dependents.send(action)
|
|
112
116
|
end
|
|
@@ -123,10 +127,11 @@ module Lite
|
|
|
123
127
|
dependents = reflection_dependents(table_name)
|
|
124
128
|
next if dependents.nil?
|
|
125
129
|
|
|
126
|
-
action =
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
+
action =
|
|
131
|
+
case reflection_marco(reflection)
|
|
132
|
+
when "one" then :unarchive
|
|
133
|
+
when "many" then :unarchive_all
|
|
134
|
+
end
|
|
130
135
|
|
|
131
136
|
dependents.send(action)
|
|
132
137
|
end
|
|
@@ -142,7 +147,7 @@ module Lite
|
|
|
142
147
|
end
|
|
143
148
|
|
|
144
149
|
def reflection_marco(reflection)
|
|
145
|
-
reflection.macro.to_s.gsub(
|
|
150
|
+
reflection.macro.to_s.gsub("has_", "")
|
|
146
151
|
end
|
|
147
152
|
|
|
148
153
|
def updatable?
|
data/lib/lite/archive/methods.rb
CHANGED
data/lib/lite/archive/railtie.rb
CHANGED
|
@@ -4,7 +4,7 @@ module Lite
|
|
|
4
4
|
module Archive
|
|
5
5
|
class Railtie < Rails::Railtie
|
|
6
6
|
|
|
7
|
-
initializer
|
|
7
|
+
initializer "lite-archive.configure_locales" do |app|
|
|
8
8
|
Array(app.config.i18n.available_locales).each do |locale|
|
|
9
9
|
path = File.expand_path("../../../locales/#{locale}.yml", __FILE__)
|
|
10
10
|
next unless File.file?(path)
|
data/lib/lite/archive/version.rb
CHANGED
data/lib/lite/archive.rb
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
4
|
-
require
|
|
3
|
+
require "active_record" unless defined?(ActiveRecord)
|
|
4
|
+
require "active_support" unless defined?(ActiveSupport)
|
|
5
5
|
|
|
6
|
-
require
|
|
6
|
+
require "generators/lite/archive/install_generator" if defined?(Rails::Generators)
|
|
7
7
|
|
|
8
|
-
require
|
|
9
|
-
require
|
|
10
|
-
require
|
|
11
|
-
require
|
|
12
|
-
require
|
|
13
|
-
require
|
|
14
|
-
require
|
|
15
|
-
require
|
|
8
|
+
require "lite/archive/railtie" if defined?(Rails::Railtie)
|
|
9
|
+
require "lite/archive/version"
|
|
10
|
+
require "lite/archive/configuration"
|
|
11
|
+
require "lite/archive/schema_statement"
|
|
12
|
+
require "lite/archive/table_definition"
|
|
13
|
+
require "lite/archive/methods"
|
|
14
|
+
require "lite/archive/scopes"
|
|
15
|
+
require "lite/archive/base"
|
data/lite-archive.gemspec
CHANGED
|
@@ -1,55 +1,49 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
lib = File.expand_path(
|
|
3
|
+
lib = File.expand_path("../lib", __FILE__)
|
|
4
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
|
-
require
|
|
5
|
+
require "lite/archive/version"
|
|
6
6
|
|
|
7
7
|
Gem::Specification.new do |spec|
|
|
8
|
-
spec.name =
|
|
8
|
+
spec.name = "lite-archive"
|
|
9
9
|
spec.version = Lite::Archive::VERSION
|
|
10
|
-
spec.authors = [
|
|
10
|
+
spec.authors = ["Juan Gomez"]
|
|
11
11
|
spec.email = %w[j.gomez@drexed.com]
|
|
12
12
|
|
|
13
|
-
spec.summary =
|
|
14
|
-
spec.homepage =
|
|
15
|
-
spec.license =
|
|
13
|
+
spec.summary = "Archive (soft-delete) ActiveRecord database records"
|
|
14
|
+
spec.homepage = "http://drexed.github.io/lite-archive"
|
|
15
|
+
spec.license = "MIT"
|
|
16
16
|
|
|
17
17
|
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
|
18
18
|
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
'source_code_uri' => 'https://github.com/drexed/lite-archive'
|
|
25
|
-
)
|
|
26
|
-
else
|
|
27
|
-
raise 'RubyGems 2.0 or newer is required to protect against ' \
|
|
28
|
-
'public gem pushes.'
|
|
29
|
-
end
|
|
19
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
|
20
|
+
spec.metadata["changelog_uri"] = "https://github.com/drexed/lite-archive/blob/master/CHANGELOG.md"
|
|
21
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
|
22
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
|
23
|
+
spec.metadata["source_code_uri"] = "https://github.com/drexed/lite-archive"
|
|
30
24
|
|
|
31
25
|
# Specify which files should be added to the gem when it is released.
|
|
32
26
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
33
|
-
spec.files = Dir.chdir(File.expand_path(
|
|
27
|
+
spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
|
|
34
28
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
35
29
|
end
|
|
36
|
-
spec.bindir =
|
|
30
|
+
spec.bindir = "exe"
|
|
37
31
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
38
32
|
spec.require_paths = %w[lib]
|
|
39
33
|
|
|
40
|
-
spec.add_runtime_dependency
|
|
41
|
-
spec.add_runtime_dependency
|
|
34
|
+
spec.add_runtime_dependency "activerecord"
|
|
35
|
+
spec.add_runtime_dependency "activesupport"
|
|
42
36
|
|
|
43
|
-
spec.add_development_dependency
|
|
44
|
-
spec.add_development_dependency
|
|
45
|
-
spec.add_development_dependency
|
|
46
|
-
spec.add_development_dependency
|
|
47
|
-
spec.add_development_dependency
|
|
48
|
-
spec.add_development_dependency
|
|
49
|
-
spec.add_development_dependency
|
|
50
|
-
spec.add_development_dependency
|
|
51
|
-
spec.add_development_dependency
|
|
52
|
-
spec.add_development_dependency
|
|
53
|
-
spec.add_development_dependency
|
|
54
|
-
spec.add_development_dependency
|
|
37
|
+
spec.add_development_dependency "bundler"
|
|
38
|
+
spec.add_development_dependency "database_cleaner"
|
|
39
|
+
spec.add_development_dependency "fasterer"
|
|
40
|
+
spec.add_development_dependency "generator_spec"
|
|
41
|
+
spec.add_development_dependency "rake"
|
|
42
|
+
spec.add_development_dependency "rspec"
|
|
43
|
+
spec.add_development_dependency "rspec-rails"
|
|
44
|
+
spec.add_development_dependency "rubocop"
|
|
45
|
+
spec.add_development_dependency "rubocop-performance"
|
|
46
|
+
spec.add_development_dependency "rubocop-rake"
|
|
47
|
+
spec.add_development_dependency "rubocop-rspec"
|
|
48
|
+
spec.add_development_dependency "sqlite3"
|
|
55
49
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: lite-archive
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Juan Gomez
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2022-11-19 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activerecord
|
|
@@ -217,7 +217,6 @@ files:
|
|
|
217
217
|
- ".gitignore"
|
|
218
218
|
- ".rspec"
|
|
219
219
|
- ".rubocop.yml"
|
|
220
|
-
- ".travis.yml"
|
|
221
220
|
- CHANGELOG.md
|
|
222
221
|
- CODE_OF_CONDUCT.md
|
|
223
222
|
- Gemfile
|
|
@@ -244,7 +243,12 @@ files:
|
|
|
244
243
|
homepage: http://drexed.github.io/lite-archive
|
|
245
244
|
licenses:
|
|
246
245
|
- MIT
|
|
247
|
-
metadata:
|
|
246
|
+
metadata:
|
|
247
|
+
allowed_push_host: https://rubygems.org
|
|
248
|
+
changelog_uri: https://github.com/drexed/lite-archive/blob/master/CHANGELOG.md
|
|
249
|
+
homepage_uri: http://drexed.github.io/lite-archive
|
|
250
|
+
rubygems_mfa_required: 'true'
|
|
251
|
+
source_code_uri: https://github.com/drexed/lite-archive
|
|
248
252
|
post_install_message:
|
|
249
253
|
rdoc_options: []
|
|
250
254
|
require_paths:
|
|
@@ -260,7 +264,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
260
264
|
- !ruby/object:Gem::Version
|
|
261
265
|
version: '0'
|
|
262
266
|
requirements: []
|
|
263
|
-
rubygems_version: 3.
|
|
267
|
+
rubygems_version: 3.3.26
|
|
264
268
|
signing_key:
|
|
265
269
|
specification_version: 4
|
|
266
270
|
summary: Archive (soft-delete) ActiveRecord database records
|
data/.travis.yml
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
sudo: false
|
|
2
|
-
language: ruby
|
|
3
|
-
cache: bundler
|
|
4
|
-
rvm:
|
|
5
|
-
- 2.5
|
|
6
|
-
- 2.6
|
|
7
|
-
- 2.7
|
|
8
|
-
- ruby-head
|
|
9
|
-
matrix:
|
|
10
|
-
fast_finish: true
|
|
11
|
-
allow_failures:
|
|
12
|
-
- rvm: ruby-head
|
|
13
|
-
before_install:
|
|
14
|
-
- gem update --system
|
|
15
|
-
- gem install bundler
|
|
16
|
-
install:
|
|
17
|
-
- bundle install --jobs=3 --retry=3
|
|
18
|
-
script:
|
|
19
|
-
- bundle exec rspec
|
|
20
|
-
- bundle exec rubocop
|
|
21
|
-
- bundle exec fasterer
|
|
22
|
-
notifications:
|
|
23
|
-
email: false
|
|
24
|
-
slack:
|
|
25
|
-
secure: VdEizS3D0v5cSQBgPDMooq5mGwf2sYQALnt0MF3dr/hLK36IeLI6FR5GkiC+qWXW88QnDm2i1HbgeM5SlSUZfU9EOGrnGIzCUe690q7XTI+N35P/Op59Ma1fOV2ojEjg2wwJzUVtfS6fYMzI0mfNAN8gg9ASN1fHtCnh5VK9AECC4931b0TxdwrJECRE+hzDSRGcmjqX+Nam0jj6GzJt0blBMcHpJAd+Ari/gGcb5v3+rBdzPLY79/HECZvzPORFDOqtgWKHv7gWQ44HEyGwJXp0fzBb1G1CCAwxMldqv7Jz4lPaADulFaAJOPMaNjTYIajhhjW8nG4zAav45cFhctpW/9YujYHBe9PnhmFFSopBGTJzXYJnAmTzrDKupZOxrLvx4ZWR+DRs7F6v73rPlKYpnmaEmy+wbp4Awju7Shc64veuCohw7sVMivUH634u6Yd5ezh22nyTb541i1RPwy0T7E9nRBXTz5sFnymQGUuvUfBPpRwDJUVxsBO86xofHHzY7YgKo2haiZP07wRX0LVxrnVyD31vMY+oTMAlvHK2WzGnX757gcXbwtLEb3qD8WYEi0mGVHSVo3CvYggv3mTCpgR2U3t+Wl9oxFDbNNQulaomSheBWVBcncYeftBLdZcLFTBtx/WbT/rppS4XxYrVkfGraJ17P6kGnhJCbmo=
|