active_archive 2.4.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1d0ebc9e989d471df9de539fa9f0a7189ec4ab04
4
- data.tar.gz: 9229273513eee94f67040e1c792513b17debaecc
3
+ metadata.gz: 4a27cc51a169e10a792eb78e458c4f578f86000b
4
+ data.tar.gz: 3b1f2b28213632d8d97a26b77cb1c3e0fbb79079
5
5
  SHA512:
6
- metadata.gz: 81203ac1d02c7d50a8880d701c2967c56ba4ac264c36e8848bcf2b23c318b6e15c426764444b23966008e177e60810635ae156461e78b3575dde6d074d80ac2b
7
- data.tar.gz: fbdd2b2f21ed9e83e9a359cf0a513e28b37b2a53a4eb62f84f2f18eb667eecc87685c5004126a4fd9cee174f3432c860f5de500495b9da7ea36d5fcfd2741de8
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
@@ -6,4 +6,4 @@
6
6
  /doc/
7
7
  /pkg/
8
8
  /spec/reports/
9
- /tmp/
9
+ /tmp/
data/.rspec CHANGED
@@ -1,4 +1,4 @@
1
1
  --backtrace
2
2
  --color
3
3
  --format progress
4
- --order random
4
+ --order random
data/.travis.yml CHANGED
@@ -10,4 +10,4 @@ notifications:
10
10
  on_success: never
11
11
  rvm:
12
12
  - ruby-head
13
- script: 'bundle exec rake'
13
+ script: 'bundle exec rake'
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
@@ -1,4 +1,4 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in active_archive.gemspec
4
- gemspec
4
+ gemspec
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/active_archive.svg)](http://badge.fury.io/rb/active_archive)
4
4
  [![Build Status](https://travis-ci.org/drexed/active_archive.svg?branch=master)](https://travis-ci.org/drexed/active_archive)
5
- [![Coverage Status](https://coveralls.io/repos/drexed/active_archive/badge.png)](https://coveralls.io/r/drexed/active_archive)
5
+ [![Coverage Status](https://coveralls.io/repos/github/drexed/active_archive/badge.svg?branch=master)](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 'active_archive'
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
- 1. Fork it ( https://github.com/[my-github-username]/active_archive/fork )
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 'Add some feature'`)
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 a new Pull Request
99
+ 5. Create new Pull Request
data/Rakefile CHANGED
@@ -1,3 +1,3 @@
1
1
  require "bundler/gem_tasks"
2
2
 
3
- task default: :spec
3
+ task default: :spec
@@ -1,21 +1,21 @@
1
1
  # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
2
+ lib = File.expand_path("../lib", __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'active_archive/version'
4
+ require "active_archive/version"
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "active_archive"
8
- spec.version = ActiveArchive::VERSION
9
- spec.authors = ["Juan Gomez"]
10
- spec.email = ["j.gomez@drexed.com"]
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 = %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"
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 = `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) }
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
@@ -11,4 +11,4 @@ require "active_archive"
11
11
  # Pry.start
12
12
 
13
13
  require "irb"
14
- IRB.start
14
+ IRB.start
data/bin/rake CHANGED
@@ -2,15 +2,15 @@
2
2
  #
3
3
  # This file was generated by Bundler.
4
4
  #
5
- # The application 'rake' is installed as part of a gem, and
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 'pathname'
10
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
9
+ require "pathname"
10
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
11
11
  Pathname.new(__FILE__).realpath)
12
12
 
13
- require 'rubygems'
14
- require 'bundler/setup'
13
+ require "rubygems"
14
+ require "bundler/setup"
15
15
 
16
- load Gem.bin_path('rake', 'rake')
16
+ load Gem.bin_path("rake", "rake")
data/bin/setup CHANGED
@@ -4,4 +4,4 @@ IFS=$'\n\t'
4
4
 
5
5
  bundle install
6
6
 
7
- # Do any other automated setup that you need to do here
7
+ # Do any other automated setup that you need to do here
@@ -2,4 +2,4 @@ en:
2
2
  active_archive:
3
3
  archival:
4
4
  archived: "Archived"
5
- unarchived: "Unarchived"
5
+ unarchived: "Unarchived"
@@ -1,5 +1,5 @@
1
- require 'active_archive/version'
2
- require 'active_archive/configuration'
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 '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'
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
- ActiveRecord::Base.send(:include, ActiveArchive::Base)
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 'rails'
35
+ require "rails"
34
36
 
35
37
  module ActiveArchive
36
38
  class Railtie < ::Rails::Railtie
37
39
 
38
- initializer 'active_archive' do |app|
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
@@ -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).lazy.each { |r| r.call(options) }
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
- begin
57
- notify_observers(callback)
58
- rescue NoMethodError => e
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
- record_id = (self.respond_to?(:parent_id) && self.parent_id.present?) ? parent_id : id
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
- self.class.reflections.lazy.each do |key, reflection|
80
- if reflection.options[:dependent] == :destroy
81
- next unless records = self.send(key)
82
- if records.respond_to?(:size)
83
- next unless records.size > 0
84
- else
85
- records = [] << records
86
- end
87
- dependent_record = records.first
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
- return(dependent_records)
91
+
92
+ dependent_records
93
93
  end
94
94
 
95
95
  def permanently_delete_records(dependent_records)
96
- dependent_records.lazy.each do |klass, ids|
97
- ids.lazy.each do |id|
98
- record = begin
99
- klass.unscoped.find(id)
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 = block.call
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
- ->(_validate) { unarchive_destroyed_dependent_records(_validate) },
119
- ->(_validate) { run_callbacks(:unarchive) { set_archived_at(nil, _validate) } }
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
- 'destroy'.freeze == reflection.options[:dependent].to_s && reflection.klass.archivable?
127
+ "destroy" == reflection.options[:dependent].to_s && reflection.klass.archivable?
126
128
  end.each do |name, reflection|
127
- cardinality = reflection.macro.to_s.gsub('has_'.freeze, ''.freeze).to_sym
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.lazy.each { |d| d.unarchive(force) }
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('@attributes'.freeze)
148
- rescue Exception => e
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 === force) ? force[:force] : (:force == force)
166
+ force.is_a?(Hash) ? force[:force] : (:force == force)
165
167
  end
166
168
 
167
169
  def should_ignore_validations?(force)
168
- (Hash === force) && (false == force[:validate])
170
+ force.is_a?(Hash) && (false == force[:validate])
169
171
  end
170
172
 
171
173
  def should_unarchive_parent_first?(order)
172
- (Hash === order) && (true == order[:reverse])
174
+ order.is_a?(Hash) && (true == order[:reverse])
173
175
  end
174
176
 
175
177
  end
176
- end
178
+ end
@@ -3,8 +3,8 @@ class ActiveArchive::Configuration
3
3
  attr_accessor :all_records_archivable, :dependent_record_window
4
4
 
5
5
  def initialize
6
- @all_records_archivable = false
6
+ @all_records_archivable = false
7
7
  @dependent_record_window = 3.seconds
8
8
  end
9
9
 
10
- end
10
+ end
@@ -2,7 +2,7 @@ module ActiveArchive
2
2
  module Methods
3
3
 
4
4
  def archivable?
5
- columns.lazy.detect { |c| c.name == 'archived_at'.freeze }
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.lazy.each { |r| r.unarchive }
13
+ (conditions ? where(conditions) : all).to_a.each { |r| r.unarchive }
14
14
  end
15
15
 
16
16
  end
17
- end
17
+ end
@@ -10,4 +10,4 @@ module ActiveArchive
10
10
  end
11
11
 
12
12
  end
13
- end
13
+ end
@@ -11,4 +11,4 @@ module ActiveRecord
11
11
 
12
12
  end
13
13
  end
14
- end
14
+ end
@@ -1,3 +1,3 @@
1
1
  module ActiveArchive
2
- VERSION = "2.4.0"
3
- end
2
+ VERSION = "3.0.0"
3
+ end
@@ -1,12 +1,12 @@
1
- require 'rails/generators'
1
+ require "rails/generators"
2
2
 
3
3
  module ActiveArchive
4
4
  class InstallGenerator < Rails::Generators::Base
5
- source_root File.expand_path('../templates', __FILE__)
5
+ source_root File.expand_path("../templates", __FILE__)
6
6
 
7
7
  def copy_initializer_file
8
- copy_file('install.rb'.freeze, 'config/initializers/active_archive.rb'.freeze)
8
+ copy_file("install.rb", "config/initializers/active_archive.rb")
9
9
  end
10
10
 
11
11
  end
12
- end
12
+ end
@@ -1,4 +1,4 @@
1
1
  ActiveArchive.configure do |config|
2
- config.all_records_archivable = false
2
+ config.all_records_archivable = false
3
3
  config.dependent_record_window = 3.seconds
4
- end
4
+ 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: 2.4.0
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-01-07 00:00:00.000000000 Z
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.5.1
174
+ rubygems_version: 2.6.4
175
175
  signing_key:
176
176
  specification_version: 4
177
177
  summary: Gem for soft-deleting ActiveRecord objects.