plain_query 0.2.0 → 0.2.1
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/README.md +6 -8
- data/lib/plain_query/instance_methods.rb +1 -1
- data/lib/plain_query/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: 70c15cb5669c0f7794a193a259ba966f97f6017fafa8db1d6b97ce63d4e2ef17
|
4
|
+
data.tar.gz: 37d7a7c0e1109f138a0e9860dd956002b6b68de6eb6b54cac501b62783b01bff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d24c959954d7cf9a25fb512ab3c603c46a168891e84a120c980fda12675e398a81af9362cd1cc203b3f97342f611b7446663277ad793fb8f03fe6d01045d808c
|
7
|
+
data.tar.gz: 9cfb9811e1c2bd1ff8c8832481f4b1d084da6526c6562ef8547f4b48759ae669d58cabe00e1a4d97fdf9f6248e0f53d2c4c1a23c58990068bf30289e6bda1658
|
data/README.md
CHANGED
@@ -41,17 +41,13 @@ class UsersQuery
|
|
41
41
|
include PlainQuery::Base(model: User)
|
42
42
|
|
43
43
|
query_step :filter_by_activity, if: -> { options[:only_active] }
|
44
|
-
query_step :filter_by_phone_presence
|
44
|
+
query_step :filter_by_phone_presence, query: UsersWithPhoneQuery
|
45
45
|
query_step :order_by_name
|
46
46
|
|
47
47
|
def filter_by_activity
|
48
48
|
relation.where(active: true)
|
49
49
|
end
|
50
50
|
|
51
|
-
def filter_by_phone_presence
|
52
|
-
relation.where.not(phone: nil)
|
53
|
-
end
|
54
|
-
|
55
51
|
def order_by_name
|
56
52
|
relation.order(name: :asc)
|
57
53
|
end
|
@@ -81,13 +77,15 @@ It declares which query change method will be executed, condition of execution a
|
|
81
77
|
It has several arguments:
|
82
78
|
|
83
79
|
```rb
|
84
|
-
query_step STEP_NAME,
|
80
|
+
query_step STEP_NAME, EXECUTION_OPTIONS
|
85
81
|
```
|
86
82
|
|
87
83
|
`STEP_NAME` is a name of method which will be executed.
|
88
84
|
|
89
|
-
`
|
90
|
-
|
85
|
+
`EXECUTION_OPTIONS` is a collection of options related with step execution.
|
86
|
+
Available two types of options:
|
87
|
+
`Condition` - allows or denieds execution of query step. Type of condition can be `if:` or `unless:`. Condition definition can be proc (lambda) or some query object method name. Result of query object method used in condition will be used as a boolean value.
|
88
|
+
`Nested query` - realises DI for current query object by `query` key. It can execute any class which has call method and returns relation.
|
91
89
|
|
92
90
|
### Using in Active Record model scope.
|
93
91
|
First of all you need to set correct model name inside query object.
|
@@ -28,7 +28,7 @@ module PlainQuery
|
|
28
28
|
end
|
29
29
|
|
30
30
|
# Executes query mutation and checks that step returns ActiveRecord::Relation
|
31
|
-
mutated_query = send(step_name)
|
31
|
+
mutated_query = params[:query] ? params[:query].call(@relation, @options) : send(step_name)
|
32
32
|
unless mutated_query.is_a?(ActiveRecord::Relation)
|
33
33
|
raise(StandardError, 'Scope must be ActiveRecord::Relation')
|
34
34
|
end
|
data/lib/plain_query/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: plain_query
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- gl-pv
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-12-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|