status_assignable 0.1.6 → 0.1.9

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: 7ef254faf75f8c06ff1ea2f1efffc4e2e46478639c34ce33b04adf754d6eb8e4
4
- data.tar.gz: 36c35683c70b07612c84a793be219f548bb816f3fcdeef58995227a37872f59c
3
+ metadata.gz: aef552d3cca4f8121e6188c08222f9d0b0a88816262d003c71755b748c4e19e1
4
+ data.tar.gz: 3019ed8df1d42c3bd0d53acb9b29d88cb8f0a59554a90f6962dbde4284b50c28
5
5
  SHA512:
6
- metadata.gz: 64cf25ad1f86c9a1f86087ad2b2c53a4aec9b2da405dd9846f4c3f0e0efac04e6315644b83a1e3f53561b5daefbf8bb58023519ea15330b8309df9945e2c0111
7
- data.tar.gz: 4b8d9eec55606e7e29b2526cefcc5a2786d4e982852e87760894b1ca2e18e6f1057c17dac2a2a43103c40c0ddf52c9d0ef6944f924f5e1f865d75187dc400def
6
+ metadata.gz: c142597d84b756833b6504a99dbf2778a9507b0018e25e31b560932eb29a858ec1137492bac32661f17c4385ef6059500b616844d700657b761c1688d58fc1a6
7
+ data.tar.gz: c11b8bd832d61e8a48e9032094c5723087fb496d29dcda8fd6d144544b3f9c03ee8f7fd169cfa0a1dad77df12cb5441bc40a881e796d6715b2b84038613e6ec7
data/README.md CHANGED
@@ -88,10 +88,12 @@ class User < ApplicationRecord
88
88
 
89
89
  has_many :posts, dependent: :destroy, archive: :callbacks
90
90
  has_many :comments, dependent: :delete_all, archive: :assign
91
+ has_many :favorites, dependent: :destroy, archive: :destroy
92
+ has_many :tasks, dependent: :nullify, archive: :nullify
91
93
  end
92
94
  ```
93
95
 
94
- The `archive` option can be set to `:callbacks` or `:assign`. If set to `:callbacks`, the associated records will be archived using `soft_destroy`. If set to `:assign`, the associated records will have their status columns assigned directly.
96
+ The `archive` option can be set to `:callbacks`, `:assign`, `:destroy` or `:nullify`. If set to `:callbacks`, the associated records will be archived using `soft_destroy`. If set to `:assign`, the associated records will have their status columns assigned directly. If set to `:destroy`, the associated records will be directly destroyed. If set to `:nullify`, the associated record's foreign key will be set to nil.
95
97
 
96
98
  It is important that the associations also are `StatusAssignable`!
97
99
 
@@ -5,7 +5,7 @@ module StatusAssignable
5
5
  # The values accepted by the :archive option are :callbacks and :assign.
6
6
  module Association
7
7
  CUSTOM_VALID_OPTIONS = [:archive].freeze
8
- VALID_ARCHIVE_OPTIONS = %i[callbacks assign].freeze
8
+ VALID_ARCHIVE_OPTIONS = %i[callbacks assign destroy nullify].freeze
9
9
 
10
10
  private
11
11
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module StatusAssignable
4
- VERSION = '0.1.6'
4
+ VERSION = '0.1.9'
5
5
  end
@@ -97,6 +97,8 @@ module StatusAssignable
97
97
  case archive_procedure
98
98
  when :callbacks then callbacks_method(query)
99
99
  when :assign then assign_method(query)
100
+ when :destroy then destroy_method(query)
101
+ when :nullify then nullify_method(query, association)
100
102
  end
101
103
  end
102
104
  end
@@ -108,6 +110,18 @@ module StatusAssignable
108
110
  def assign_method(query)
109
111
  query.respond_to?(:update_all) ? query.update_all(archive_params) : query&.update_columns(archive_params)
110
112
  end
113
+
114
+ def destroy_method(query)
115
+ query.respond_to?(:each) ? query.each(&:destroy) : query&.destroy
116
+ end
117
+
118
+ def nullify_method(query, association)
119
+ if query.respond_to?(:update_all)
120
+ query.update_all(association.foreign_key => nil)
121
+ else
122
+ query&.update_column(association.foreign_key, nil)
123
+ end
124
+ end
111
125
  end
112
126
  end
113
127
 
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: status_assignable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tien
8
+ autorequire:
8
9
  bindir: exe
9
10
  cert_chain: []
10
- date: 2025-03-03 00:00:00.000000000 Z
11
+ date: 2026-09-10 00:00:00.000000000 Z
11
12
  dependencies:
12
13
  - !ruby/object:Gem::Dependency
13
14
  name: rails
@@ -29,6 +30,7 @@ dependencies:
29
30
  - - "<"
30
31
  - !ruby/object:Gem::Version
31
32
  version: '9'
33
+ description:
32
34
  email:
33
35
  - tieeeeen1994@gmail.com
34
36
  executables: []
@@ -52,6 +54,7 @@ licenses:
52
54
  metadata:
53
55
  homepage_uri: https://github.com/tieeeeen1994/rails-status-assignable
54
56
  rubygems_mfa_required: 'true'
57
+ post_install_message:
55
58
  rdoc_options: []
56
59
  require_paths:
57
60
  - lib
@@ -66,7 +69,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
66
69
  - !ruby/object:Gem::Version
67
70
  version: '0'
68
71
  requirements: []
69
- rubygems_version: 3.6.5
72
+ rubygems_version: 3.0.3.1
73
+ signing_key:
70
74
  specification_version: 4
71
75
  summary: Allows models to be assigned a status.
72
76
  test_files: []