readymade 0.3.8 → 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 +4 -0
- data/Gemfile.lock +7 -7
- data/README.md +1 -0
- data/lib/readymade/model/filterable.rb +27 -2
- 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
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)
|
@@ -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.
|
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
@@ -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/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
|