readymade 0.3.8 → 0.4.0
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/CHANGELOG.md +8 -0
- data/Gemfile.lock +20 -8
- data/README.md +21 -0
- data/lib/readymade/model/filterable.rb +25 -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: 8483000673ca7a63fffc4b90f4daa53b22888b868e4c1cd4bf5777d1a343971f
|
4
|
+
data.tar.gz: bb4439b66aa4aa72b31ccba62ae4c79a79506e91ce20499091c5971beac915b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e021c22b31b459638c2cdc4fafeb40b6eb0743f3164894f67ff5781f5108a52b524f297b08f6a4b9ec339552874e033af511076160cda43050b0d65913e77f20
|
7
|
+
data.tar.gz: 511da71335a13117bc9b9c7e12a05ef868e2e0c48405a9ae70d24fe791067a73a123891d324a5c1ef9c119e173bbfc211fd62fc1e89820b5fc67a4d8be86268f
|
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.4.0] - 2024-02-23
|
5
|
+
|
6
|
+
* Add `Reaymade::Model::ValidatableEnum` to validate enum values
|
7
|
+
|
8
|
+
## [0.3.9] - 2024-01-04
|
9
|
+
|
10
|
+
* Update `Readymade::Model::Filterable` to support and/or joins
|
11
|
+
|
4
12
|
## [0.3.8] - 2023-10-06
|
5
13
|
|
6
14
|
* Add `conisder_success` argument to Response
|
data/Gemfile.lock
CHANGED
@@ -1,31 +1,42 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
readymade (0.
|
4
|
+
readymade (0.4.0)
|
5
5
|
activejob
|
6
6
|
activemodel
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
activejob (7.
|
12
|
-
activesupport (= 7.
|
11
|
+
activejob (7.1.3)
|
12
|
+
activesupport (= 7.1.3)
|
13
13
|
globalid (>= 0.3.6)
|
14
|
-
activemodel (7.
|
15
|
-
activesupport (= 7.
|
16
|
-
activesupport (7.
|
14
|
+
activemodel (7.1.3)
|
15
|
+
activesupport (= 7.1.3)
|
16
|
+
activesupport (7.1.3)
|
17
|
+
base64
|
18
|
+
bigdecimal
|
17
19
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
20
|
+
connection_pool (>= 2.2.5)
|
21
|
+
drb
|
18
22
|
i18n (>= 1.6, < 2)
|
19
23
|
minitest (>= 5.1)
|
24
|
+
mutex_m
|
20
25
|
tzinfo (~> 2.0)
|
26
|
+
base64 (0.2.0)
|
27
|
+
bigdecimal (3.1.6)
|
21
28
|
byebug (11.1.3)
|
22
|
-
concurrent-ruby (1.2.
|
29
|
+
concurrent-ruby (1.2.3)
|
30
|
+
connection_pool (2.4.1)
|
23
31
|
diff-lcs (1.4.4)
|
32
|
+
drb (2.2.0)
|
33
|
+
ruby2_keywords
|
24
34
|
globalid (1.2.1)
|
25
35
|
activesupport (>= 6.1)
|
26
36
|
i18n (1.14.1)
|
27
37
|
concurrent-ruby (~> 1.0)
|
28
|
-
minitest (5.
|
38
|
+
minitest (5.22.1)
|
39
|
+
mutex_m (0.2.0)
|
29
40
|
rake (13.0.6)
|
30
41
|
rspec (3.10.0)
|
31
42
|
rspec-core (~> 3.10.0)
|
@@ -40,6 +51,7 @@ GEM
|
|
40
51
|
diff-lcs (>= 1.2.0, < 2.0)
|
41
52
|
rspec-support (~> 3.10.0)
|
42
53
|
rspec-support (3.10.3)
|
54
|
+
ruby2_keywords (0.0.5)
|
43
55
|
tzinfo (2.0.6)
|
44
56
|
concurrent-ruby (~> 1.0)
|
45
57
|
|
data/README.md
CHANGED
@@ -284,6 +284,27 @@ 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
|
288
|
+
```
|
289
|
+
|
290
|
+
### Readymade::Model::ValidatableEnum
|
291
|
+
|
292
|
+
Instead of raised error when enum value is not valid, it adds error to the record
|
293
|
+
|
294
|
+
```ruby
|
295
|
+
class User < ApplicationRecord
|
296
|
+
include Readymade::Model::ValidatableEnum
|
297
|
+
|
298
|
+
enum status: { inactive: 0, active: 10 }
|
299
|
+
enum role: { customer: 0, admin: 10 }
|
300
|
+
validatable_enum :status, :role
|
301
|
+
end
|
302
|
+
```
|
303
|
+
|
304
|
+
```ruby
|
305
|
+
user = User.new(status: 'archived', role: 'superadmin')
|
306
|
+
user.validate # false
|
307
|
+
user.errors.full_messages # ["Role 'superadmin' is not a valid role", "Status 'archived' is not a valid status"]
|
287
308
|
```
|
288
309
|
|
289
310
|
## Development
|
@@ -20,13 +20,36 @@ module Readymade
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
def
|
23
|
+
def send_chain_with_or(methods, scope = self)
|
24
|
+
return scope if methods.blank?
|
25
|
+
|
26
|
+
conditions = []
|
27
|
+
if methods.respond_to?(:keys)
|
28
|
+
methods.each do |scope_name, argument|
|
29
|
+
conditions << send(scope_name, argument)
|
30
|
+
end
|
31
|
+
else
|
32
|
+
methods.each do |scope_name|
|
33
|
+
conditions << send(scope_name)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
where(id: conditions.inject(:or).select(:id))
|
38
|
+
end
|
39
|
+
|
40
|
+
def filter_collection(filtering_params, chain_with: :and)
|
24
41
|
filtering_params.permit! if filtering_params.respond_to?(:permit)
|
25
42
|
|
26
43
|
regular_params = filtering_params.select { |_key, value| value.present? }.to_h
|
27
44
|
custom_params = filtering_params.to_h.select { |_key, value| value.is_a?(String) && value.start_with?('without_') }.values
|
28
45
|
|
29
|
-
|
46
|
+
if chain_with == :and
|
47
|
+
send_chain(regular_params, send_chain(custom_params)).all
|
48
|
+
elsif chain_with.to_sym == :or
|
49
|
+
send_chain_with_or(regular_params, send_chain_with_or(custom_params)).all
|
50
|
+
else
|
51
|
+
none
|
52
|
+
end
|
30
53
|
end
|
31
54
|
end
|
32
55
|
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.
|
4
|
+
version: 0.4.0
|
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-02-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: byebug
|