active_archive 2.4.0 → 3.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 +4 -4
- data/.coveralls.yml +1 -1
- data/.gitignore +1 -1
- data/.rspec +1 -1
- data/.travis.yml +1 -1
- data/CODE_OF_CONDUCT.md +1 -1
- data/Gemfile +2 -2
- data/README.md +7 -5
- data/Rakefile +1 -1
- data/active_archive.gemspec +13 -13
- data/bin/console +1 -1
- data/bin/rake +6 -6
- data/bin/setup +1 -1
- data/config/locales/en.yml +1 -1
- data/lib/active_archive.rb +13 -11
- data/lib/active_archive/base.rb +41 -39
- data/lib/active_archive/configuration.rb +2 -2
- data/lib/active_archive/methods.rb +3 -3
- data/lib/active_archive/scopes.rb +1 -1
- data/lib/active_archive/table_definition.rb +1 -1
- data/lib/active_archive/version.rb +2 -2
- data/lib/generators/active_archive/install_generator.rb +4 -4
- data/lib/generators/active_archive/templates/install.rb +2 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a27cc51a169e10a792eb78e458c4f578f86000b
|
4
|
+
data.tar.gz: 3b1f2b28213632d8d97a26b77cb1c3e0fbb79079
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 534b1317fa36b6dc2822dc783b4817b7ff3db6c8b7255298808ee0f014a18aa3aaec0a2ddb9dd1914317559a2fde0fdec6f792161a79949b8031b83ee429bc4e
|
7
|
+
data.tar.gz: b7dba38f3a22e7ad42d5b4a9714fe1be10bf460e7c2ab6d4764b6675f339090af17c1b01242a0ad6dadbe9c587395b4a3dd99895b4d64fb439642f99c4f2bff3
|
data/.coveralls.yml
CHANGED
@@ -1 +1 @@
|
|
1
|
-
service_name: travis-ci
|
1
|
+
service_name: travis-ci
|
data/.gitignore
CHANGED
data/.rspec
CHANGED
data/.travis.yml
CHANGED
data/CODE_OF_CONDUCT.md
CHANGED
@@ -10,4 +10,4 @@ Project maintainers have the right and responsibility to remove, edit, or reject
|
|
10
10
|
|
11
11
|
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
12
|
|
13
|
-
This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
[](http://badge.fury.io/rb/active_archive)
|
4
4
|
[](https://travis-ci.org/drexed/active_archive)
|
5
|
-
[](https://coveralls.io/github/drexed/active_archive?branch=master)
|
6
6
|
|
7
7
|
ActiveArchive is a library for preventing database records from being destroyed.
|
8
8
|
|
@@ -11,7 +11,7 @@ ActiveArchive is a library for preventing database records from being destroyed.
|
|
11
11
|
Add this line to your application's Gemfile:
|
12
12
|
|
13
13
|
```ruby
|
14
|
-
gem
|
14
|
+
gem "active_archive"
|
15
15
|
```
|
16
16
|
|
17
17
|
And then execute:
|
@@ -90,8 +90,10 @@ User.unarchived.all #=> returns only unarchived record
|
|
90
90
|
|
91
91
|
## Contributing
|
92
92
|
|
93
|
-
|
93
|
+
Your contribution is welcome.
|
94
|
+
|
95
|
+
1. Fork it
|
94
96
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
95
|
-
3. Commit your changes (`git commit -am '
|
97
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
96
98
|
4. Push to the branch (`git push origin my-new-feature`)
|
97
|
-
5. Create
|
99
|
+
5. Create new Pull Request
|
data/Rakefile
CHANGED
data/active_archive.gemspec
CHANGED
@@ -1,21 +1,21 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
lib = File.expand_path(
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require
|
4
|
+
require "active_archive/version"
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name
|
8
|
-
spec.version
|
9
|
-
spec.authors
|
10
|
-
spec.email
|
7
|
+
spec.name = "active_archive"
|
8
|
+
spec.version = ActiveArchive::VERSION
|
9
|
+
spec.authors = ["Juan Gomez"]
|
10
|
+
spec.email = ["j.gomez@drexed.com"]
|
11
11
|
|
12
|
-
spec.summary
|
13
|
-
spec.description
|
14
|
-
spec.homepage
|
12
|
+
spec.summary = %q{Gem for soft-deleting ActiveRecord objects.}
|
13
|
+
spec.description = %q{Prevent database records from being destroyed.}
|
14
|
+
spec.homepage = "https://github.com/drexed/active_archive"
|
15
15
|
|
16
|
-
spec.files
|
17
|
-
spec.bindir
|
18
|
-
spec.executables
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
19
|
spec.require_paths = ["lib", "support"]
|
20
20
|
|
21
21
|
spec.add_runtime_dependency "rails"
|
@@ -27,4 +27,4 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.add_development_dependency "sqlite3"
|
28
28
|
spec.add_development_dependency "database_cleaner"
|
29
29
|
spec.add_development_dependency "generator_spec"
|
30
|
-
end
|
30
|
+
end
|
data/bin/console
CHANGED
data/bin/rake
CHANGED
@@ -2,15 +2,15 @@
|
|
2
2
|
#
|
3
3
|
# This file was generated by Bundler.
|
4
4
|
#
|
5
|
-
# The application
|
5
|
+
# The application "rake" is installed as part of a gem, and
|
6
6
|
# this file is here to facilitate running it.
|
7
7
|
#
|
8
8
|
|
9
|
-
require
|
10
|
-
ENV[
|
9
|
+
require "pathname"
|
10
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
11
11
|
Pathname.new(__FILE__).realpath)
|
12
12
|
|
13
|
-
require
|
14
|
-
require
|
13
|
+
require "rubygems"
|
14
|
+
require "bundler/setup"
|
15
15
|
|
16
|
-
load Gem.bin_path(
|
16
|
+
load Gem.bin_path("rake", "rake")
|
data/bin/setup
CHANGED
data/config/locales/en.yml
CHANGED
data/lib/active_archive.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "active_archive/version"
|
2
|
+
require "active_archive/configuration"
|
3
3
|
|
4
4
|
module ActiveArchive
|
5
5
|
|
@@ -21,21 +21,23 @@ module ActiveArchive
|
|
21
21
|
|
22
22
|
end
|
23
23
|
|
24
|
-
require
|
25
|
-
require
|
26
|
-
require
|
27
|
-
require
|
28
|
-
require
|
24
|
+
require "active_archive/table_definition"
|
25
|
+
require "active_archive/methods"
|
26
|
+
require "active_archive/scopes"
|
27
|
+
require "active_archive/base"
|
28
|
+
require "generators/active_archive/install_generator"
|
29
29
|
|
30
|
-
|
30
|
+
ActiveSupport.on_load(:active_record) do
|
31
|
+
ActiveRecord::Base.send(:include, ActiveArchive::Base)
|
32
|
+
end
|
31
33
|
|
32
34
|
if defined?(Rails)
|
33
|
-
require
|
35
|
+
require "rails"
|
34
36
|
|
35
37
|
module ActiveArchive
|
36
38
|
class Railtie < ::Rails::Railtie
|
37
39
|
|
38
|
-
initializer
|
40
|
+
initializer "active_archive" do |app|
|
39
41
|
ActiveArchive::Railtie.instance_eval do
|
40
42
|
[app.config.i18n.available_locales].flatten.each do |locale|
|
41
43
|
(I18n.load_path << path(locale)) if File.file?(path(locale))
|
@@ -51,4 +53,4 @@ if defined?(Rails)
|
|
51
53
|
|
52
54
|
end
|
53
55
|
end
|
54
|
-
end
|
56
|
+
end
|
data/lib/active_archive/base.rb
CHANGED
@@ -35,7 +35,7 @@ module ActiveArchive
|
|
35
35
|
|
36
36
|
def unarchive(options=nil)
|
37
37
|
with_transaction_returning_status do
|
38
|
-
(should_unarchive_parent_first?(options) ? unarchival.reverse : unarchival).
|
38
|
+
(should_unarchive_parent_first?(options) ? unarchival.reverse : unarchival).each { |r| r.call(options) }
|
39
39
|
self
|
40
40
|
end
|
41
41
|
end
|
@@ -53,11 +53,9 @@ module ActiveArchive
|
|
53
53
|
private
|
54
54
|
|
55
55
|
def attempt_notifying_observers(callback)
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
# RETURN
|
60
|
-
end
|
56
|
+
notify_observers(callback)
|
57
|
+
rescue NoMethodError
|
58
|
+
# RETURN
|
61
59
|
end
|
62
60
|
|
63
61
|
def destroy_with_active_archive(force=nil)
|
@@ -70,36 +68,35 @@ module ActiveArchive
|
|
70
68
|
end
|
71
69
|
|
72
70
|
def get_archived_record
|
73
|
-
|
74
|
-
self.class.unscoped.find(record_id)
|
71
|
+
self.class.unscoped.find(id)
|
75
72
|
end
|
76
73
|
|
77
74
|
def get_dependent_records
|
78
75
|
dependent_records = {}
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
next if dependent_record.nil?
|
89
|
-
dependent_records[dependent_record.class] = records.map(&:id)
|
76
|
+
|
77
|
+
self.class.reflections.each do |key, reflection|
|
78
|
+
next unless reflection.options[:dependent] == :destroy
|
79
|
+
next unless records = send(key)
|
80
|
+
|
81
|
+
if records.respond_to? :size
|
82
|
+
next unless records.size > 0
|
83
|
+
else
|
84
|
+
records = [] << records
|
90
85
|
end
|
86
|
+
|
87
|
+
dependent_record = records.first
|
88
|
+
next if dependent_record.nil?
|
89
|
+
dependent_records[dependent_record.class] = records.map(&:id)
|
91
90
|
end
|
92
|
-
|
91
|
+
|
92
|
+
dependent_records
|
93
93
|
end
|
94
94
|
|
95
95
|
def permanently_delete_records(dependent_records)
|
96
|
-
dependent_records.
|
97
|
-
ids.
|
98
|
-
record =
|
99
|
-
|
100
|
-
rescue ::ActiveRecord::RecordNotFound
|
101
|
-
next
|
102
|
-
end
|
96
|
+
dependent_records.each do |klass, ids|
|
97
|
+
ids.each do |id|
|
98
|
+
record = klass.unscoped.where(klass.primary_key => id).first
|
99
|
+
next unless record
|
103
100
|
record.archived_at = nil
|
104
101
|
record.destroy(:force)
|
105
102
|
end
|
@@ -108,23 +105,28 @@ module ActiveArchive
|
|
108
105
|
|
109
106
|
def permanently_delete_records_after(&block)
|
110
107
|
dependent_records = get_dependent_records
|
111
|
-
dependent_results =
|
108
|
+
dependent_results = yield
|
112
109
|
permanently_delete_records(dependent_records) if dependent_results
|
113
110
|
return(dependent_results)
|
114
111
|
end
|
115
112
|
|
116
113
|
def unarchival
|
117
114
|
[
|
118
|
-
->(
|
119
|
-
->(
|
115
|
+
->(validate) { unarchive_destroyed_dependent_records(validate) },
|
116
|
+
->(validate) do
|
117
|
+
run_callbacks(:unarchive) do
|
118
|
+
set_archived_at(nil, validate)
|
119
|
+
return(true)
|
120
|
+
end
|
121
|
+
end
|
120
122
|
]
|
121
123
|
end
|
122
124
|
|
123
125
|
def unarchive_destroyed_dependent_records(force = nil)
|
124
126
|
self.class.reflections.select do |name, reflection|
|
125
|
-
|
127
|
+
"destroy" == reflection.options[:dependent].to_s && reflection.klass.archivable?
|
126
128
|
end.each do |name, reflection|
|
127
|
-
cardinality = reflection.macro.to_s.gsub(
|
129
|
+
cardinality = reflection.macro.to_s.gsub("has_", "").to_sym
|
128
130
|
case cardinality
|
129
131
|
when :many
|
130
132
|
records = (archived_at ? set_record_window(send(name), name, reflection) : send(name))
|
@@ -132,7 +134,7 @@ module ActiveArchive
|
|
132
134
|
self.class.unscoped { records = [] << send(name) }
|
133
135
|
end
|
134
136
|
|
135
|
-
[records].flatten.compact.
|
137
|
+
[records].flatten.compact.each { |d| d.unarchive(force) }
|
136
138
|
send(name, :reload)
|
137
139
|
end
|
138
140
|
end
|
@@ -144,8 +146,8 @@ module ActiveArchive
|
|
144
146
|
|
145
147
|
begin
|
146
148
|
should_ignore_validations?(force) ? record.save(validate: false) : record.save!
|
147
|
-
@attributes = record.instance_variable_get(
|
148
|
-
rescue
|
149
|
+
@attributes = record.instance_variable_get("@attributes")
|
150
|
+
rescue => e
|
149
151
|
record.destroy
|
150
152
|
raise(e)
|
151
153
|
end
|
@@ -161,16 +163,16 @@ module ActiveArchive
|
|
161
163
|
end
|
162
164
|
|
163
165
|
def should_force_destroy?(force)
|
164
|
-
(Hash
|
166
|
+
force.is_a?(Hash) ? force[:force] : (:force == force)
|
165
167
|
end
|
166
168
|
|
167
169
|
def should_ignore_validations?(force)
|
168
|
-
(Hash
|
170
|
+
force.is_a?(Hash) && (false == force[:validate])
|
169
171
|
end
|
170
172
|
|
171
173
|
def should_unarchive_parent_first?(order)
|
172
|
-
(Hash
|
174
|
+
order.is_a?(Hash) && (true == order[:reverse])
|
173
175
|
end
|
174
176
|
|
175
177
|
end
|
176
|
-
end
|
178
|
+
end
|
@@ -2,7 +2,7 @@ module ActiveArchive
|
|
2
2
|
module Methods
|
3
3
|
|
4
4
|
def archivable?
|
5
|
-
columns.
|
5
|
+
columns.detect { |c| c.name == "archived_at" }
|
6
6
|
end
|
7
7
|
|
8
8
|
def archive_all(conditions=nil)
|
@@ -10,8 +10,8 @@ module ActiveArchive
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def unarchive_all(conditions=nil)
|
13
|
-
(conditions ? where(conditions) : all).to_a.
|
13
|
+
(conditions ? where(conditions) : all).to_a.each { |r| r.unarchive }
|
14
14
|
end
|
15
15
|
|
16
16
|
end
|
17
|
-
end
|
17
|
+
end
|
@@ -1,3 +1,3 @@
|
|
1
1
|
module ActiveArchive
|
2
|
-
VERSION = "
|
3
|
-
end
|
2
|
+
VERSION = "3.0.0"
|
3
|
+
end
|
@@ -1,12 +1,12 @@
|
|
1
|
-
require
|
1
|
+
require "rails/generators"
|
2
2
|
|
3
3
|
module ActiveArchive
|
4
4
|
class InstallGenerator < Rails::Generators::Base
|
5
|
-
source_root File.expand_path(
|
5
|
+
source_root File.expand_path("../templates", __FILE__)
|
6
6
|
|
7
7
|
def copy_initializer_file
|
8
|
-
copy_file(
|
8
|
+
copy_file("install.rb", "config/initializers/active_archive.rb")
|
9
9
|
end
|
10
10
|
|
11
11
|
end
|
12
|
-
end
|
12
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_archive
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.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: 2016-
|
11
|
+
date: 2016-06-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -171,7 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
171
171
|
version: '0'
|
172
172
|
requirements: []
|
173
173
|
rubyforge_project:
|
174
|
-
rubygems_version: 2.
|
174
|
+
rubygems_version: 2.6.4
|
175
175
|
signing_key:
|
176
176
|
specification_version: 4
|
177
177
|
summary: Gem for soft-deleting ActiveRecord objects.
|