readymade 0.3.8 → 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: d23f98bdcf35999cfdad659cf75fb3e5f103da34508ec1b05cd18eb45465751e
4
- data.tar.gz: 15d45fadf8ad68e6603959d6c6ae51b43407733c7458aa4ca20c94ad76bf6fd3
3
+ metadata.gz: 37150c92279da3c7ecb29441fccbf188572039fe69712cf99824121c8ebeb889
4
+ data.tar.gz: f94ab00a9af6b37097958c1a386932f8667e7e37ea55ec30530a2e92a423738d
5
5
  SHA512:
6
- metadata.gz: f5ec8fa06c4198d1281decc771ea8a9ed721a4ca75f17f983b82fc4dd000ad67a3c3b7116e57ae0324edc266055da18a394f36431c7ca2ed68a4a3fb29f31538
7
- data.tar.gz: 5b14c12db646986bb0746e783ca04f075739f84b23f3ef2db12595c993108586350a11aff2ce3bc3257b3861c8625ac487d91a84a8a6baf0608f2175b55595c8
6
+ metadata.gz: b7b562dd8614ca64c8821d71c89ecff73c9556d8c8b5ea4ed95046ba8841354e193ae5e6d61ce05e673cdf8c8ef3946322165761862ca1aee7d8cdc44ecc6b99
7
+ data.tar.gz: 2608dd0e7def9ea166ec4c0edb391a748d02602e4c8a2e6fd3f0a536397fae5c0e286330fdd07901196f4316bdcf578630f14c5ff985e32896fee35a8f284cb1
data/CHANGELOG.md CHANGED
@@ -1,6 +1,10 @@
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
+
4
8
  ## [0.3.8] - 2023-10-06
5
9
 
6
10
  * Add `conisder_success` argument to Response
data/Gemfile.lock CHANGED
@@ -1,19 +1,19 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- readymade (0.3.8)
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.7.2)
12
- activesupport (= 7.0.7.2)
11
+ activejob (7.0.8)
12
+ activesupport (= 7.0.8)
13
13
  globalid (>= 0.3.6)
14
- activemodel (7.0.7.2)
15
- activesupport (= 7.0.7.2)
16
- activesupport (7.0.7.2)
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)
@@ -25,7 +25,7 @@ GEM
25
25
  activesupport (>= 6.1)
26
26
  i18n (1.14.1)
27
27
  concurrent-ruby (~> 1.0)
28
- minitest (5.19.0)
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
@@ -284,6 +284,7 @@ end
284
284
 
285
285
  ```ruby
286
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
287
288
  ```
288
289
 
289
290
  ## Development
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Readymade
4
- VERSION = '0.3.8'
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.8
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-10-06 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