permanent_records 4.2.8 → 5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2a557f2f7f287f2cbd1990950e869d2a943e5c8593df0dbd41520790d049f3b0
4
- data.tar.gz: 8ebc139901710c0599e36873217a70ad936918a1dbf93520797099b2c7e8e40d
3
+ metadata.gz: 6f7d5e533d3ea6f107b72b635d5c58871601a782d759b41f6c5578f7f556d54f
4
+ data.tar.gz: 1c1ccdac5a7812cdd3dbaec043580ba62ea82e0858d9a8b56850a58703c7e79c
5
5
  SHA512:
6
- metadata.gz: 0d547b27a573c1abdc3a85c7803d56452f95c8a8a6f485476f52e18d2173ad67e25e5b9904ad4b9fe6a22fdecaf9ba57b1866a432f940917841202ace3fc9c0a
7
- data.tar.gz: e4a8d014f056e37ef0e941cc52251c63acc935051e5103822dd7f8942ce9c086bbad6fc0a20ce687c0f8e35d5d48b12dd2affbf859baab89e83318c6c49f6ca1
6
+ metadata.gz: 42910c3d809df7cda9876f1e752da136055640053682bde499b1a33f7f9142222fe22c7fefe1fae3750ed0180179582a2eb3d6a05321ef9303be37bc93e79a3a
7
+ data.tar.gz: f2a06abe6da337d41c610a7e539516e4b71ede008f644bc75db3c1bd4805f43c526783ffff18275d4871cf5713619f172f4ed6e9c139080aeded2d47c001bc63
@@ -0,0 +1,28 @@
1
+ name: Ruby Gem
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+
8
+ jobs:
9
+ build:
10
+ name: gem publishing
11
+ runs-on: ubuntu-latest
12
+
13
+ steps:
14
+ - uses: actions/checkout@master
15
+ - name: Set up Ruby 2.6
16
+ uses: actions/setup-ruby@v1
17
+ with:
18
+ ruby-version: 2.6.x
19
+
20
+ - name: Publish to RubyGems
21
+ run: |
22
+ mkdir -p $HOME/.gem
23
+ touch $HOME/.gem/credentials
24
+ chmod 0600 $HOME/.gem/credentials
25
+ printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
26
+ bin/gempush-if-changed
27
+ env:
28
+ GEM_HOST_API_KEY: ${{secrets.RUBYGEMS_AUTH_TOKEN}}
@@ -0,0 +1,32 @@
1
+ name: Tests
2
+
3
+ on: push
4
+
5
+ jobs:
6
+ ci:
7
+ name: CI
8
+ runs-on: ubuntu-latest
9
+ strategy:
10
+ matrix:
11
+ ruby:
12
+ - '2.3.x'
13
+ - '2.4.x'
14
+ - '2.5.x'
15
+ - '2.6.x'
16
+ rails:
17
+ - '5.0.7.2'
18
+ - '5.1.7'
19
+ - '5.2.3'
20
+ steps:
21
+ - name: Install system dependencies
22
+ run: sudo apt-get install -y libsqlite3-dev
23
+ - uses: actions/checkout@master
24
+ - name: Setup ruby
25
+ uses: actions/setup-ruby@v1
26
+ with:
27
+ ruby-version: ${{ matrix.ruby }}
28
+ architecture: 'x64'
29
+ - run: gem install bundler && bundle && bundle exec rake
30
+ env:
31
+ AR_TEST_VERSION: ${{ matrix.rails }}
32
+
data/.rubocop.yml CHANGED
@@ -1,9 +1,11 @@
1
+ require: rubocop-performance
2
+
1
3
  inherit_from: .rubocop_todo.yml
2
4
 
3
5
  AllCops:
4
6
  Exclude:
5
7
  - bin/*
6
- TargetRubyVersion: 2.0
8
+ TargetRubyVersion: 2.2
7
9
 
8
10
  Metrics/BlockLength:
9
11
  Enabled: false
data/.rubocop_todo.yml CHANGED
@@ -1,12 +1,7 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2019-10-09 11:48:30 +0200 using RuboCop version 0.50.0.
3
+ # on 2019-10-15 13:32:11 +0200 using RuboCop version 0.68.1.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
7
7
  # versions of RuboCop, may require this file to be generated again.
8
-
9
- # Offense count: 15
10
- Lint/AmbiguousBlockAssociation:
11
- Exclude:
12
- - 'spec/permanent_records_spec.rb'
data/.travis.yml CHANGED
@@ -1,8 +1,11 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.0.0-p648
4
3
  - 2.2.10
5
4
  - 2.3.8
5
+ - 2.4.9
6
+ - 2.5.7
7
+ - 2.6.5
6
8
  env:
7
- - AR_TEST_VERSION: 4.2.0
8
- - AR_TEST_VERSION: 4.2.11.1
9
+ - AR_TEST_VERSION: 5.0.7.2
10
+ - AR_TEST_VERSION: 5.1.7
11
+ - AR_TEST_VERSION: 5.2.3
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # PermanentRecords (Rails 4.2)
1
+ # PermanentRecords (Rails 5)
2
2
 
3
3
  [http://github.com/JackDanger/permanent_records/](http://github.com/JackDanger/permanent_records/)
4
4
 
data/README.rst CHANGED
@@ -1,4 +1,4 @@
1
- PermanentRecords (Rails 4.2)
1
+ PermanentRecords (Rails 5)
2
2
  =============================
3
3
 
4
4
  http://github.com/JackDanger/permanent_records/
data/VERSION CHANGED
@@ -1 +1 @@
1
- 4.2.8
1
+ 5.0.0
@@ -0,0 +1,11 @@
1
+ #!/bin/bash
2
+
3
+ set -x
4
+ if git diff --name-only HEAD..HEAD^ | egrep -q '^VERSION$'; then
5
+ # The VERSION file changed in the last commit, build the gem and push
6
+ gem build *.gemspec
7
+ gem push *.gem
8
+ version=$(cat VERSION)
9
+ git tag ${version}
10
+ git push origin ${version}
11
+ fi
@@ -0,0 +1 @@
1
+ .github/workflows/test.yml
@@ -51,7 +51,7 @@ module PermanentRecords
51
51
  if !is_permanent? || PermanentRecords.should_force_destroy?(force)
52
52
  permanently_delete_records_after { super() }
53
53
  else
54
- destroy_with_permanent_records force
54
+ destroy_with_permanent_records(force)
55
55
  end
56
56
  end
57
57
  end
@@ -68,7 +68,7 @@ module PermanentRecords
68
68
  set_deleted_at(nil, validate)
69
69
  # increment all associated counters for counter cache
70
70
  each_counter_cache do |assoc_class, counter_cache_column, assoc_id|
71
- assoc_class.increment_counter counter_cache_column, assoc_id
71
+ assoc_class.increment_counter(counter_cache_column, assoc_id)
72
72
  end
73
73
  true
74
74
  end
@@ -81,9 +81,9 @@ module PermanentRecords
81
81
  end
82
82
 
83
83
  # rubocop:disable Metrics/MethodLength
84
- # rubocop:disable Lint/RescueWithoutErrorClass
85
84
  def set_deleted_at(value, force = nil)
86
85
  return self unless is_permanent?
86
+
87
87
  record = get_deleted_record
88
88
  record.deleted_at = value
89
89
  begin
@@ -98,14 +98,14 @@ module PermanentRecords
98
98
  end
99
99
 
100
100
  @attributes = record.instance_variable_get('@attributes')
101
- rescue => e
101
+ rescue StandardError => e
102
102
  # trigger dependent record destruction (they were revived before this
103
103
  # record, which cannot be revived due to validations)
104
104
  record.destroy
105
105
  raise e
106
106
  end
107
107
  end
108
- # rubocop:enable Lint/RescueWithoutErrorClass
108
+
109
109
  # rubocop:enable Metrics/MethodLength
110
110
 
111
111
  def each_counter_cache
@@ -116,9 +116,7 @@ module PermanentRecords
116
116
 
117
117
  associated_class = association.class
118
118
 
119
- yield(associated_class,
120
- reflection.counter_cache_column,
121
- send(reflection.foreign_key))
119
+ yield(associated_class, reflection.counter_cache_column, send(reflection.foreign_key))
122
120
  end
123
121
  end
124
122
 
@@ -131,7 +129,7 @@ module PermanentRecords
131
129
  set_deleted_at(Time.now, force)
132
130
  # decrement all associated counters for counter cache
133
131
  each_counter_cache do |assoc_class, counter_cache_column, assoc_id|
134
- assoc_class.decrement_counter counter_cache_column, assoc_id
132
+ assoc_class.decrement_counter(counter_cache_column, assoc_id)
135
133
  end
136
134
  end
137
135
  true
@@ -143,18 +141,16 @@ module PermanentRecords
143
141
  def add_record_window(_request, name, reflection)
144
142
  send(name).unscope(where: :deleted_at).where(
145
143
  [
146
- "#{reflection.quoted_table_name}.deleted_at > ?" \
144
+ "#{reflection.klass.quoted_table_name}.deleted_at > ?" \
147
145
  ' AND ' \
148
- "#{reflection.quoted_table_name}.deleted_at < ?",
146
+ "#{reflection.klass.quoted_table_name}.deleted_at < ?",
149
147
  deleted_at - PermanentRecords.dependent_record_window,
150
148
  deleted_at + PermanentRecords.dependent_record_window
151
149
  ]
152
150
  )
153
151
  end
154
152
 
155
- # TODO: Feel free to refactor this without polluting the ActiveRecord
156
- # namespace.
157
- # rubocop:disable Metrics/AbcSize
153
+ # TODO: Feel free to refactor this without polluting the ActiveRecord namespace.
158
154
  def revive_destroyed_dependent_records(force = nil)
159
155
  destroyed_dependent_relations.each do |relation|
160
156
  relation.to_a.each { |destroyed_dependent_record| destroyed_dependent_record.try(:revive, force) }
@@ -165,15 +161,14 @@ module PermanentRecords
165
161
  # rubocop:disable Metrics/MethodLength
166
162
  def destroyed_dependent_relations
167
163
  PermanentRecords.dependent_permanent_reflections(self.class).map do |name, relation|
168
- cardinality = relation.macro.to_s.gsub('has_', '').to_sym
169
- case cardinality
170
- when :many
164
+ case relation.macro.to_sym
165
+ when :has_many
171
166
  if deleted_at
172
167
  add_record_window(send(name), name, relation)
173
168
  else
174
169
  send(name).unscope(where: :deleted_at)
175
170
  end
176
- when :one, :belongs_to
171
+ when :has_one, :belongs_to
177
172
  self.class.unscoped { Array(send(name)) }
178
173
  end
179
174
  end
@@ -194,6 +189,7 @@ module PermanentRecords
194
189
  .reduce({}) do |records, (key, _)|
195
190
  found = Array(send(key)).compact
196
191
  next records if found.empty?
192
+
197
193
  records.update found.first.class => found.map(&:id)
198
194
  end
199
195
  end
@@ -218,6 +214,7 @@ module PermanentRecords
218
214
  ids.each do |id|
219
215
  record = klass.unscoped.where(klass.primary_key => id).first
220
216
  next unless record
217
+
221
218
  record.deleted_at = nil
222
219
  record.destroy(:force)
223
220
  end
@@ -282,5 +279,9 @@ module PermanentRecords
282
279
  end
283
280
 
284
281
  ActiveSupport.on_load(:active_record) do
285
- ActiveRecord::Base.send :include, PermanentRecords::ActiveRecord
282
+ ActiveRecord::Base.send(:include, PermanentRecords::ActiveRecord)
283
+
284
+ if [ActiveRecord::VERSION::MAJOR, ActiveRecord::VERSION::MINOR] == [5, 2] || ActiveRecord::VERSION::MAJOR > 5
285
+ require 'permanent_records/active_record_5_2'
286
+ end
286
287
  end
@@ -0,0 +1,40 @@
1
+ # rubocop:disable Metrics/AbcSize
2
+ # Support destroy for rails belongs_to assocations.
3
+ module HandlePermanentRecordsDestroyedInBelongsToAssociation
4
+ def handle_dependency
5
+ return unless load_target
6
+
7
+ case options[:dependent]
8
+ when :destroy
9
+ target.destroy
10
+ raise ActiveRecord::Rollback if target.respond_to?(:deleted?) && !target.deleted?
11
+ else
12
+ target.send(options[:dependent])
13
+ end
14
+ end
15
+ end
16
+
17
+ # rubocop:disable Metrics/MethodLength
18
+ # rubocop:disable Metrics/CyclomaticComplexity
19
+ # Support destroy for rails 5.2. has_on associations.
20
+ module HandlePermanentRecordsDestroyedInHasOneAssociation
21
+ def delete(method = options[:dependent])
22
+ return unless load_target
23
+
24
+ case method
25
+ when :delete
26
+ target.delete
27
+ when :destroy
28
+ target.destroyed_by_association = reflection
29
+ target.destroy
30
+ throw(:abort) if target.respond_to?(:deleted?) && !target.deleted?
31
+ when :nullify
32
+ target.update_columns(reflection.foreign_key => nil) if target.persisted?
33
+ end
34
+ end
35
+ end
36
+ # rubocop:enable Metrics/CyclomaticComplexity
37
+ # rubocop:enable Metrics/MethodLength
38
+ # rubocop:enable Metrics/AbcSize
39
+ ActiveRecord::Associations::BelongsToAssociation.prepend(HandlePermanentRecordsDestroyedInBelongsToAssociation)
40
+ ActiveRecord::Associations::HasOneAssociation.prepend(HandlePermanentRecordsDestroyedInHasOneAssociation)
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
10
10
  s.description = <<-DESCRIPTION
11
11
  Never Lose Data. Rather than deleting rows this sets Record#deleted_at and
12
12
  gives you all the scopes you need to work with your data.
13
- DESCRIPTION
13
+ DESCRIPTION
14
14
  s.email = 'github@jackcanty.com'
15
15
  s.extra_rdoc_files = [
16
16
  'LICENSE',
@@ -26,12 +26,13 @@ DESCRIPTION
26
26
  ver = ENV['AR_TEST_VERSION']
27
27
  ver = ver.dup.chomp if ver
28
28
 
29
- s.add_runtime_dependency 'activerecord', ver || '>= 4.2.0'
30
- s.add_runtime_dependency 'activesupport', ver || '>= 4.2.0'
29
+ s.add_runtime_dependency 'activerecord', ver || '>= 5.0.0'
30
+ s.add_runtime_dependency 'activesupport', ver || '>= 5.0.0'
31
31
  s.add_development_dependency 'database_cleaner', '>= 1.5.1'
32
32
  s.add_development_dependency 'pry-byebug'
33
33
  s.add_development_dependency 'rake' # For Travis-ci
34
34
  s.add_development_dependency 'rspec', '>= 3.5.0'
35
- s.add_development_dependency 'rubocop', '~> 0.50.0' # freeze to ensure ruby 2.0 compatibility
36
- s.add_development_dependency 'sqlite3', '~> 1.3.6' # freeze to ensure specs are working
35
+ s.add_development_dependency 'rubocop', '~> 0.68.0' # freeze to ensure ruby 2.2 compatibility
36
+ s.add_development_dependency 'rubocop-performance'
37
+ s.add_development_dependency 'sqlite3', '~> 1.3.13' # freeze to ensure specs are working
37
38
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: permanent_records
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.8
4
+ version: 5.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jack Danger Canty
@@ -17,36 +17,36 @@ authors:
17
17
  autorequire:
18
18
  bindir: bin
19
19
  cert_chain: []
20
- date: 2019-10-15 00:00:00.000000000 Z
20
+ date: 2019-10-16 00:00:00.000000000 Z
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
23
  name: activerecord
24
24
  requirement: !ruby/object:Gem::Requirement
25
25
  requirements:
26
- - - '='
26
+ - - ">="
27
27
  - !ruby/object:Gem::Version
28
- version: 4.2.11.1
28
+ version: 5.0.0
29
29
  type: :runtime
30
30
  prerelease: false
31
31
  version_requirements: !ruby/object:Gem::Requirement
32
32
  requirements:
33
- - - '='
33
+ - - ">="
34
34
  - !ruby/object:Gem::Version
35
- version: 4.2.11.1
35
+ version: 5.0.0
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: activesupport
38
38
  requirement: !ruby/object:Gem::Requirement
39
39
  requirements:
40
- - - '='
40
+ - - ">="
41
41
  - !ruby/object:Gem::Version
42
- version: 4.2.11.1
42
+ version: 5.0.0
43
43
  type: :runtime
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
46
46
  requirements:
47
- - - '='
47
+ - - ">="
48
48
  - !ruby/object:Gem::Version
49
- version: 4.2.11.1
49
+ version: 5.0.0
50
50
  - !ruby/object:Gem::Dependency
51
51
  name: database_cleaner
52
52
  requirement: !ruby/object:Gem::Requirement
@@ -109,28 +109,42 @@ dependencies:
109
109
  requirements:
110
110
  - - "~>"
111
111
  - !ruby/object:Gem::Version
112
- version: 0.50.0
112
+ version: 0.68.0
113
113
  type: :development
114
114
  prerelease: false
115
115
  version_requirements: !ruby/object:Gem::Requirement
116
116
  requirements:
117
117
  - - "~>"
118
118
  - !ruby/object:Gem::Version
119
- version: 0.50.0
119
+ version: 0.68.0
120
+ - !ruby/object:Gem::Dependency
121
+ name: rubocop-performance
122
+ requirement: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ type: :development
128
+ prerelease: false
129
+ version_requirements: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
120
134
  - !ruby/object:Gem::Dependency
121
135
  name: sqlite3
122
136
  requirement: !ruby/object:Gem::Requirement
123
137
  requirements:
124
138
  - - "~>"
125
139
  - !ruby/object:Gem::Version
126
- version: 1.3.6
140
+ version: 1.3.13
127
141
  type: :development
128
142
  prerelease: false
129
143
  version_requirements: !ruby/object:Gem::Requirement
130
144
  requirements:
131
145
  - - "~>"
132
146
  - !ruby/object:Gem::Version
133
- version: 1.3.6
147
+ version: 1.3.13
134
148
  description: |2
135
149
  Never Lose Data. Rather than deleting rows this sets Record#deleted_at and
136
150
  gives you all the scopes you need to work with your data.
@@ -142,6 +156,8 @@ extra_rdoc_files:
142
156
  - README.md
143
157
  files:
144
158
  - ".document"
159
+ - ".github/workflows/gempush.yml"
160
+ - ".github/workflows/test.yml"
145
161
  - ".gitignore"
146
162
  - ".rubocop.yml"
147
163
  - ".rubocop_todo.yml"
@@ -154,9 +170,12 @@ files:
154
170
  - README.rst
155
171
  - Rakefile
156
172
  - VERSION
173
+ - bin/gempush-if-changed
157
174
  - bin/rspec
158
175
  - ci
176
+ - github-actions-test.yml
159
177
  - lib/permanent_records.rb
178
+ - lib/permanent_records/active_record_5_2.rb
160
179
  - permanent_records.gemspec
161
180
  homepage: https://github.com/JackDanger/permanent_records
162
181
  licenses: