readymade 0.3.7 → 0.3.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: a99833ca151368c750c36d51cdd6be713210f846b1cdd78b2ba533b188fa3d63
4
- data.tar.gz: f65962b9ddfebc091f7f799825e7db62e579ee8ad14c3f86afeae782f3f2692b
3
+ metadata.gz: 37150c92279da3c7ecb29441fccbf188572039fe69712cf99824121c8ebeb889
4
+ data.tar.gz: f94ab00a9af6b37097958c1a386932f8667e7e37ea55ec30530a2e92a423738d
5
5
  SHA512:
6
- metadata.gz: aefb0039b18326b3c8b47b77a8259f8957adf897bfbce727d14e2c2498652539c49ef271d1ff7281fd911e7c43577f9f2eb5c3c65f5827a6dc43f1c6a2556c7e
7
- data.tar.gz: 328f459c616399fab211b04db587ef586caf0a79a030850d14bf1b23b66e1a49944c881b656ebff0118b8bdf7c1be8d2aa98e5a7ef4a21bb15edd4dfe9b4d7f6
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.7)
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.6)
12
- activesupport (= 7.0.6)
11
+ activejob (7.0.8)
12
+ activesupport (= 7.0.8)
13
13
  globalid (>= 0.3.6)
14
- activemodel (7.0.6)
15
- activesupport (= 7.0.6)
16
- activesupport (7.0.6)
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.0)
25
- activesupport (>= 5.0)
24
+ globalid (1.2.1)
25
+ activesupport (>= 6.1)
26
26
  i18n (1.14.1)
27
27
  concurrent-ruby (~> 1.0)
28
- minitest (5.18.1)
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
@@ -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
- raise UnSuccessError unless res.try(:success?)
18
+ return res if res.try(:success?) || res.try(:consider_success?)
19
19
 
20
- res
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 filter_collection(filtering_params)
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
- send_chain(regular_params, send_chain(custom_params)).distinct
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
@@ -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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Readymade
4
- VERSION = '0.3.7'
4
+ VERSION = '0.3.9'
5
5
  end
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.7
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: 2023-08-08 00:00:00.000000000 Z
11
+ date: 2024-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug