ff1 1.2.10 → 1.2.12

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: f91cc2803c307f979e12a8704f2c760676a9e514d6457111863c43da38d6eb67
4
- data.tar.gz: 98b581e10e96f6ab07a67b976b90e30fa7b2d932fc70714bc724c46954a80efd
3
+ metadata.gz: 88b339fd29788549c9c3cdce8c1d5ee3161a47e6f42ea289f2111383d378b8f8
4
+ data.tar.gz: ffa037139280c63150b99ad4088deea33e6e10215bc703dd8d144bc617691cf1
5
5
  SHA512:
6
- metadata.gz: 73e3388d8b48f7036531829be4206fb6133a71cdc99434741af2785a70295a87699e193527a3a5796645b169b06a29bd6d53fb30952b164cc57fd196bd8928b1
7
- data.tar.gz: ad34fb9efbc131b0df8c3dafb049a3c495a264f1433d62d2826ca4cd12160178336af65bc53611066a10c2ab484cc55cc393cfdac2a65580bcabb94666683cca
6
+ metadata.gz: e7fb071f1c59b557e50ee3de7f23af7f9d88ef34b6f86429127d630ae65a74fe8759790406b219881ea4266a40f2ca1f18aa84d5db9250de4a81657158168f51
7
+ data.tar.gz: d4be47679b533d33439475af925d3498e4f92756629785d476bcad61c10d672a9bc726a0d3ea27c050357ac4cb2b006241499f39b8b21ddc724c7d7f62c92080
@@ -11,10 +11,10 @@ module FF1
11
11
 
12
12
  # Scope for active (not soft-deleted) records
13
13
  scope :ff1_active, -> do
14
- ff1_deleted_column = FF1::ActiveRecord.configuration.ff1_deleted_column
14
+ deleted_at_column = FF1::ActiveRecord.configuration.deleted_at_column
15
15
 
16
- if column_names.include?(ff1_deleted_column.to_s)
17
- where(ff1_deleted_column => [nil, false])
16
+ if column_names.include?(deleted_at_column.to_s)
17
+ where(deleted_at_column => nil)
18
18
  else
19
19
  all
20
20
  end
@@ -22,10 +22,10 @@ module FF1
22
22
 
23
23
  # Scope for soft-deleted records
24
24
  scope :ff1_deleted, -> do
25
- ff1_deleted_column = FF1::ActiveRecord.configuration.ff1_deleted_column
25
+ deleted_at_column = FF1::ActiveRecord.configuration.deleted_at_column
26
26
 
27
- if column_names.include?(ff1_deleted_column.to_s)
28
- where(ff1_deleted_column => true)
27
+ if column_names.include?(deleted_at_column.to_s)
28
+ where.not(deleted_at_column => nil)
29
29
  else
30
30
  none
31
31
  end
@@ -37,10 +37,9 @@ module FF1
37
37
  # Scope for recently deleted records
38
38
  scope :ff1_recently_deleted, ->(within: 7.days) do
39
39
  deleted_at_column = FF1::ActiveRecord.configuration.deleted_at_column
40
- ff1_deleted_column = FF1::ActiveRecord.configuration.ff1_deleted_column
41
40
 
42
- if column_names.include?(deleted_at_column.to_s) && column_names.include?(ff1_deleted_column.to_s)
43
- where(ff1_deleted_column => true)
41
+ if column_names.include?(deleted_at_column.to_s)
42
+ where.not(deleted_at_column => nil)
44
43
  .where(deleted_at_column => within.ago..Time.current)
45
44
  else
46
45
  none
@@ -50,10 +49,9 @@ module FF1
50
49
  # Scope for old deleted records (candidates for purging)
51
50
  scope :ff1_old_deleted, ->(older_than: 30.days) do
52
51
  deleted_at_column = FF1::ActiveRecord.configuration.deleted_at_column
53
- ff1_deleted_column = FF1::ActiveRecord.configuration.ff1_deleted_column
54
52
 
55
- if column_names.include?(deleted_at_column.to_s) && column_names.include?(ff1_deleted_column.to_s)
56
- where(ff1_deleted_column => true)
53
+ if column_names.include?(deleted_at_column.to_s)
54
+ where.not(deleted_at_column => nil)
57
55
  .where("#{deleted_at_column} < ?", older_than.ago)
58
56
  else
59
57
  none
@@ -40,16 +40,11 @@ module FF1
40
40
 
41
41
  # Set deletion metadata
42
42
  deleted_at_column = FF1::ActiveRecord.configuration.deleted_at_column
43
- ff1_deleted_column = FF1::ActiveRecord.configuration.ff1_deleted_column
44
43
 
45
44
  if respond_to?("#{deleted_at_column}=")
46
45
  public_send("#{deleted_at_column}=", Time.current)
47
46
  end
48
47
 
49
- if respond_to?("#{ff1_deleted_column}=")
50
- public_send("#{ff1_deleted_column}=", true)
51
- end
52
-
53
48
  # Save with validation skips to ensure deletion succeeds
54
49
  save!(validate: false)
55
50
 
@@ -79,16 +74,11 @@ module FF1
79
74
 
80
75
  transaction do
81
76
  deleted_at_column = FF1::ActiveRecord.configuration.deleted_at_column
82
- ff1_deleted_column = FF1::ActiveRecord.configuration.ff1_deleted_column
83
77
 
84
78
  if respond_to?("#{deleted_at_column}=")
85
79
  public_send("#{deleted_at_column}=", nil)
86
80
  end
87
81
 
88
- if respond_to?("#{ff1_deleted_column}=")
89
- public_send("#{ff1_deleted_column}=", false)
90
- end
91
-
92
82
  save!(validate: false)
93
83
  end
94
84
 
@@ -128,9 +118,8 @@ module FF1
128
118
  return false if ff1_config.empty?
129
119
 
130
120
  deleted_at_column = FF1::ActiveRecord.configuration.deleted_at_column
131
- ff1_deleted_column = FF1::ActiveRecord.configuration.ff1_deleted_column
132
121
 
133
- respond_to?("#{deleted_at_column}=") && respond_to?("#{ff1_deleted_column}=")
122
+ respond_to?("#{deleted_at_column}=")
134
123
  end
135
124
 
136
125
  # Irreversibly encrypt all configured columns
@@ -180,11 +169,10 @@ module FF1
180
169
  def ff1_purge_deleted(older_than: 30.days)
181
170
  deleted_at_column = FF1::ActiveRecord.configuration.deleted_at_column
182
171
 
183
- conditions = {}
184
- conditions[FF1::ActiveRecord.configuration.ff1_deleted_column] = true
185
- conditions[deleted_at_column] = ...older_than.ago if older_than
172
+ scope = where.not(deleted_at_column => nil)
173
+ scope = scope.where("#{deleted_at_column} < ?", older_than.ago) if older_than
186
174
 
187
- where(conditions).delete_all
175
+ scope.delete_all
188
176
  end
189
177
  end
190
178
  end
@@ -112,8 +112,9 @@ module FF1
112
112
 
113
113
  # Check if this record has been soft deleted with FF1
114
114
  def ff1_deleted?
115
- respond_to?(FF1::ActiveRecord.configuration.ff1_deleted_column) &&
116
- public_send(FF1::ActiveRecord.configuration.ff1_deleted_column) == true
115
+ deleted_at_column = FF1::ActiveRecord.configuration.deleted_at_column
116
+ respond_to?(deleted_at_column) &&
117
+ !public_send(deleted_at_column).nil?
117
118
  end
118
119
 
119
120
  # Check if this record is active (not soft deleted)
data/lib/ff1/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
 
3
3
  module FF1
4
4
  # Current version of the FF1 gem
5
- VERSION = '1.2.10'
5
+ VERSION = '1.2.12'
6
6
  end
@@ -56,6 +56,7 @@ module Ff1
56
56
  def generate_model_migration(model_name)
57
57
  model_class_name = model_name.camelize
58
58
  @table_name = model_name.underscore.pluralize
59
+ @migration_version = ActiveRecord::Migration.current_version
59
60
  migration_name = "add_ff1_columns_to_#{@table_name}"
60
61
 
61
62
  # Check if model exists
@@ -67,8 +68,7 @@ module Ff1
67
68
 
68
69
  # Generate migration file
69
70
  migration_template 'migration.rb.erb',
70
- "db/migrate/#{migration_name}.rb",
71
- migration_version: ActiveRecord::Migration.current_version
71
+ "db/migrate/#{migration_name}.rb"
72
72
 
73
73
  say "Migration created for #{model_class_name}", :green
74
74
  say "Run 'rails db:migrate' to apply the changes", :blue
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class <%= migration_class_name %> < ActiveRecord::Migration[<%= migration_version %>]
3
+ class <%= migration_class_name %> < ActiveRecord::Migration[<%= @migration_version %>]
4
4
  def change
5
5
  add_column :<%= @table_name %>, :<%= deleted_at_column %>, :datetime, null: true
6
6
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ff1
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.10
4
+ version: 1.2.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ahmed Abdellatif