status_assignable 0.1.8 → 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: a8774bcf6d0aea82d8bd5ff24c82ff64336c54318e2a75ef0194b73aaadebcfe
4
- data.tar.gz: 302d529d43f1fff2e8d553091431e16e1fc8b99b173d0aa0529e2bb134968161
3
+ metadata.gz: aef552d3cca4f8121e6188c08222f9d0b0a88816262d003c71755b748c4e19e1
4
+ data.tar.gz: 3019ed8df1d42c3bd0d53acb9b29d88cb8f0a59554a90f6962dbde4284b50c28
5
5
  SHA512:
6
- metadata.gz: 0a484bc3b5ba125a393af899c0b7e9cd185c52c6d8f6c5cf9f3b60b45ef46a5470db7a94156957639c0f2dd1d79a409a3c099d743b224b5e6e8905d7d997b800
7
- data.tar.gz: 74cd75459f98d148012107be61ec2109fe71bef6add3660a9a4551373ddb4f99acfcc2a9f50f6ba327199795d29cb85c1207ff33a8499608b5d07a9ddf1b5440
6
+ metadata.gz: c142597d84b756833b6504a99dbf2778a9507b0018e25e31b560932eb29a858ec1137492bac32661f17c4385ef6059500b616844d700657b761c1688d58fc1a6
7
+ data.tar.gz: c11b8bd832d61e8a48e9032094c5723087fb496d29dcda8fd6d144544b3f9c03ee8f7fd169cfa0a1dad77df12cb5441bc40a881e796d6715b2b84038613e6ec7
data/README.md CHANGED
@@ -89,10 +89,11 @@ class User < ApplicationRecord
89
89
  has_many :posts, dependent: :destroy, archive: :callbacks
90
90
  has_many :comments, dependent: :delete_all, archive: :assign
91
91
  has_many :favorites, dependent: :destroy, archive: :destroy
92
+ has_many :tasks, dependent: :nullify, archive: :nullify
92
93
  end
93
94
  ```
94
95
 
95
- The `archive` option can be set to `:callbacks`, `:assign` or `:destroy`. 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.
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.
96
97
 
97
98
  It is important that the associations also are `StatusAssignable`!
98
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 destroy].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.8'
4
+ VERSION = '0.1.9'
5
5
  end
@@ -98,6 +98,7 @@ module StatusAssignable
98
98
  when :callbacks then callbacks_method(query)
99
99
  when :assign then assign_method(query)
100
100
  when :destroy then destroy_method(query)
101
+ when :nullify then nullify_method(query, association)
101
102
  end
102
103
  end
103
104
  end
@@ -113,6 +114,14 @@ module StatusAssignable
113
114
  def destroy_method(query)
114
115
  query.respond_to?(:each) ? query.each(&:destroy) : query&.destroy
115
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
116
125
  end
117
126
  end
118
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.8
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-06 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: []