status_assignable 0.1.3 → 0.1.4
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 +4 -4
- data/README.md +7 -9
- data/lib/status_assignable/version.rb +1 -1
- data/lib/status_assignable.rb +10 -4
- data/status_assignable.gemspec +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 53bf54d853615b68d5df06ec9c6e037aff396eb1b24ebe9faeb2a4eb83e6c2d1
|
4
|
+
data.tar.gz: a193f40b4c5a5a4a5a73aa2bfb5c5bb305c86c09364ba31a8eccc462bf6fa3e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 20591c29b764534e99823c02d6b8279344bfcd0d7e1bcf63ae8f4b537fe3288599a37b5916e18bff53cde1bfd7520c6a32c26274cd8fbb844f9ea268aa8d3293
|
7
|
+
data.tar.gz: b355ff3cc3a3dc3669e613601bdaf5cd9e2152a332be9913ef4a12b860045257a5af2257d9e82a851dd9b15f3f1ab64eac0ce0e65e7cabf09e3fa1a964c5186f
|
data/README.md
CHANGED
@@ -8,13 +8,6 @@ Add this line to your application's Gemfile:
|
|
8
8
|
gem 'status_assignable', '~> 0.1'
|
9
9
|
```
|
10
10
|
|
11
|
-
After that, run the following command:
|
12
|
-
```bash
|
13
|
-
rails g status_assignable_patch
|
14
|
-
```
|
15
|
-
|
16
|
-
This will install the monkey patcher so that the gem can hook itself properly into the Rails application.
|
17
|
-
|
18
11
|
## Usage
|
19
12
|
|
20
13
|
### Model
|
@@ -24,6 +17,8 @@ In your model, add the following line:
|
|
24
17
|
```ruby
|
25
18
|
class ModelName < ApplicationRecord
|
26
19
|
include StatusAssignable
|
20
|
+
# or
|
21
|
+
has_assignable_status
|
27
22
|
|
28
23
|
# ...
|
29
24
|
end
|
@@ -66,6 +61,9 @@ You can also add your own status if need be. For example, if you want to add a `
|
|
66
61
|
```ruby
|
67
62
|
class ModelName < ApplicationRecord
|
68
63
|
include StatusAssignable[pending: 3]
|
64
|
+
# or...
|
65
|
+
has_assignable_status pending: 3
|
66
|
+
|
69
67
|
# ...
|
70
68
|
end
|
71
69
|
```
|
@@ -86,7 +84,7 @@ Model associations are also supported. For example, if you have a `User` that ha
|
|
86
84
|
|
87
85
|
```ruby
|
88
86
|
class User < ApplicationRecord
|
89
|
-
|
87
|
+
has_assignable_status
|
90
88
|
|
91
89
|
has_many :posts, dependent: :destroy, archive: :callbacks
|
92
90
|
has_many :comments, dependent: :delete_all, archive: :assign
|
@@ -105,7 +103,7 @@ There are callback hooks supported for `soft_destroy`: `before_soft_destroy`, `a
|
|
105
103
|
|
106
104
|
```ruby
|
107
105
|
class Post < ApplicationRecord
|
108
|
-
|
106
|
+
has_assignable_status
|
109
107
|
|
110
108
|
before_destroy -> { versions.destroy_all }
|
111
109
|
before_soft_destroy :update_and_unlink_versions
|
data/lib/status_assignable.rb
CHANGED
@@ -95,13 +95,19 @@ module StatusAssignable
|
|
95
95
|
archive_procedure = association.options[:archive]
|
96
96
|
query = send(association.name)
|
97
97
|
case archive_procedure
|
98
|
-
when :callbacks
|
99
|
-
|
100
|
-
when :assign
|
101
|
-
query.respond_to?(:update_all) ? query.update_all(archive_params) : query.update_columns(archive_params)
|
98
|
+
when :callbacks then callbacks_method(query)
|
99
|
+
when :assign then assign_method(query)
|
102
100
|
end
|
103
101
|
end
|
104
102
|
end
|
103
|
+
|
104
|
+
def callbacks_method(query)
|
105
|
+
query.respond_to?(:each) ? query.each(&:soft_destroy) : query&.soft_destroy
|
106
|
+
end
|
107
|
+
|
108
|
+
def assign_method(query)
|
109
|
+
query.respond_to?(:update_all) ? query.update_all(archive_params) : query&.update_columns(archive_params)
|
110
|
+
end
|
105
111
|
end
|
106
112
|
end
|
107
113
|
|
data/status_assignable.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.files = Dir.chdir(__dir__) do
|
19
19
|
`git ls-files -z`.split("\x0").reject do |f|
|
20
20
|
(File.expand_path(f) == __FILE__) ||
|
21
|
-
f.start_with?(*%w[
|
21
|
+
f.start_with?(*%w[spec/ .git .github Gemfile .vscode]) ||
|
22
22
|
f.end_with?(*%w[.gem .yml .rspec .gitignore])
|
23
23
|
end
|
24
24
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: status_assignable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tien
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-07-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -62,7 +62,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
62
62
|
- !ruby/object:Gem::Version
|
63
63
|
version: '0'
|
64
64
|
requirements: []
|
65
|
-
rubygems_version: 3.5.
|
65
|
+
rubygems_version: 3.5.11
|
66
66
|
signing_key:
|
67
67
|
specification_version: 4
|
68
68
|
summary: Allows models to be assigned a status.
|