readymade 0.3.7 → 0.3.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/Gemfile.lock +9 -9
- data/README.md +19 -0
- data/lib/readymade/action.rb +2 -2
- data/lib/readymade/model/filterable.rb +27 -2
- data/lib/readymade/response.rb +5 -0
- data/lib/readymade/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 37150c92279da3c7ecb29441fccbf188572039fe69712cf99824121c8ebeb889
|
4
|
+
data.tar.gz: f94ab00a9af6b37097958c1a386932f8667e7e37ea55ec30530a2e92a423738d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b7b562dd8614ca64c8821d71c89ecff73c9556d8c8b5ea4ed95046ba8841354e193ae5e6d61ce05e673cdf8c8ef3946322165761862ca1aee7d8cdc44ecc6b99
|
7
|
+
data.tar.gz: 2608dd0e7def9ea166ec4c0edb391a748d02602e4c8a2e6fd3f0a536397fae5c0e286330fdd07901196f4316bdcf578630f14c5ff985e32896fee35a8f284cb1
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
Changelog
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
+
## [0.3.9] - 2024-01-04
|
5
|
+
|
6
|
+
* Update `Readymade::Model::Filterable` to support and/or joins
|
7
|
+
|
8
|
+
## [0.3.8] - 2023-10-06
|
9
|
+
|
10
|
+
* Add `conisder_success` argument to Response
|
11
|
+
|
4
12
|
## [0.3.7] - 2023-08-08
|
5
13
|
|
6
14
|
* Fix invalid behaviour of `call!` method
|
data/Gemfile.lock
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
readymade (0.3.
|
4
|
+
readymade (0.3.9)
|
5
5
|
activejob
|
6
6
|
activemodel
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
activejob (7.0.
|
12
|
-
activesupport (= 7.0.
|
11
|
+
activejob (7.0.8)
|
12
|
+
activesupport (= 7.0.8)
|
13
13
|
globalid (>= 0.3.6)
|
14
|
-
activemodel (7.0.
|
15
|
-
activesupport (= 7.0.
|
16
|
-
activesupport (7.0.
|
14
|
+
activemodel (7.0.8)
|
15
|
+
activesupport (= 7.0.8)
|
16
|
+
activesupport (7.0.8)
|
17
17
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
18
18
|
i18n (>= 1.6, < 2)
|
19
19
|
minitest (>= 5.1)
|
@@ -21,11 +21,11 @@ GEM
|
|
21
21
|
byebug (11.1.3)
|
22
22
|
concurrent-ruby (1.2.2)
|
23
23
|
diff-lcs (1.4.4)
|
24
|
-
globalid (1.1
|
25
|
-
activesupport (>=
|
24
|
+
globalid (1.2.1)
|
25
|
+
activesupport (>= 6.1)
|
26
26
|
i18n (1.14.1)
|
27
27
|
concurrent-ruby (~> 1.0)
|
28
|
-
minitest (5.
|
28
|
+
minitest (5.20.0)
|
29
29
|
rake (13.0.6)
|
30
30
|
rspec (3.10.0)
|
31
31
|
rspec-core (~> 3.10.0)
|
data/README.md
CHANGED
@@ -169,6 +169,24 @@ end
|
|
169
169
|
|
170
170
|
Orders::Actions::SendNotifications.call!(order: order) # raise error if response is fail
|
171
171
|
```
|
172
|
+
|
173
|
+
### `.call` + `conisder_success: true`
|
174
|
+
```ruby
|
175
|
+
class Orders::Actions::SendNotifications < Readymade::Action
|
176
|
+
def call!
|
177
|
+
send_email
|
178
|
+
return response(:skip, consider_success: true) if skip_email?
|
179
|
+
send_push
|
180
|
+
send_slack
|
181
|
+
|
182
|
+
response(:success, record: record, any_other_data: data)
|
183
|
+
end
|
184
|
+
...
|
185
|
+
end
|
186
|
+
|
187
|
+
Orders::Actions::SendNotifications.call!(order: order) # does not raise error if skip_email? returns true
|
188
|
+
```
|
189
|
+
|
172
190
|
### `.call_async!` - runs in background and raise error unless response is success
|
173
191
|
(action must return Readymade::Response.new(:success))
|
174
192
|
|
@@ -266,6 +284,7 @@ end
|
|
266
284
|
|
267
285
|
```ruby
|
268
286
|
User.all.filter_collection({ by_status: 'active', by_role: 'manager' })
|
287
|
+
User.all.filter_collection({ by_status: 'active', by_role: 'manager' }, chain_with: :or) # active OR manager
|
269
288
|
```
|
270
289
|
|
271
290
|
## Development
|
data/lib/readymade/action.rb
CHANGED
@@ -15,9 +15,9 @@ module Readymade
|
|
15
15
|
|
16
16
|
def self.call!(*args, &block)
|
17
17
|
new(*args, &block).call!.then do |res|
|
18
|
-
|
18
|
+
return res if res.try(:success?) || res.try(:consider_success?)
|
19
19
|
|
20
|
-
|
20
|
+
raise UnSuccessError
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
@@ -2,6 +2,8 @@ require 'active_support/concern'
|
|
2
2
|
|
3
3
|
module Readymade
|
4
4
|
module Model
|
5
|
+
# frozen_string_literal: true
|
6
|
+
|
5
7
|
module Filterable
|
6
8
|
extend ActiveSupport::Concern
|
7
9
|
|
@@ -20,13 +22,36 @@ module Readymade
|
|
20
22
|
end
|
21
23
|
end
|
22
24
|
|
23
|
-
def
|
25
|
+
def send_chain_with_or(methods, scope = self)
|
26
|
+
return scope if methods.blank?
|
27
|
+
|
28
|
+
conditions = []
|
29
|
+
if methods.respond_to?(:keys)
|
30
|
+
methods.each do |scope_name, argument|
|
31
|
+
conditions << send(scope_name, argument)
|
32
|
+
end
|
33
|
+
else
|
34
|
+
methods.each do |scope_name|
|
35
|
+
conditions << send(scope_name)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
where(id: conditions.inject(:or).select(:id))
|
40
|
+
end
|
41
|
+
|
42
|
+
def filter_collection(filtering_params, chain_with: :and)
|
24
43
|
filtering_params.permit! if filtering_params.respond_to?(:permit)
|
25
44
|
|
26
45
|
regular_params = filtering_params.select { |_key, value| value.present? }.to_h
|
27
46
|
custom_params = filtering_params.to_h.select { |_key, value| value.is_a?(String) && value.start_with?('without_') }.values
|
28
47
|
|
29
|
-
|
48
|
+
if chain_with == :and
|
49
|
+
send_chain(regular_params, send_chain(custom_params)).all
|
50
|
+
elsif chain_with.to_sym == :or
|
51
|
+
send_chain_with_or(regular_params, send_chain_with_or(custom_params)).all
|
52
|
+
else
|
53
|
+
none
|
54
|
+
end
|
30
55
|
end
|
31
56
|
end
|
32
57
|
end
|
data/lib/readymade/response.rb
CHANGED
@@ -20,6 +20,7 @@ module Readymade
|
|
20
20
|
raise NonKeywordArgumentsError if args.present? && !args[0].is_a?(Hash)
|
21
21
|
|
22
22
|
@args = @data = args[0]
|
23
|
+
@consider_success = @args.delete(:consider_success) if @args.present?
|
23
24
|
|
24
25
|
define_singleton_method("#{status}?") do
|
25
26
|
true
|
@@ -30,6 +31,10 @@ module Readymade
|
|
30
31
|
args[:errors].presence || {}
|
31
32
|
end
|
32
33
|
|
34
|
+
def consider_success?
|
35
|
+
@consider_success
|
36
|
+
end
|
37
|
+
|
33
38
|
def method_missing(method_name, *args, &block)
|
34
39
|
return false if method_name.to_s.end_with?('?')
|
35
40
|
|
data/lib/readymade/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: readymade
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- OrestF
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-01-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: byebug
|