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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9fff1e9e16625d80a9f3f62e6c3cffcda79974c4bfcd41a8a2717165cb3f35f9
4
- data.tar.gz: 282cf0017c3d7b4ab771f17c67f3340a5a6d7cab1315ce821d7ffbb5e5040694
3
+ metadata.gz: 70c15cb5669c0f7794a193a259ba966f97f6017fafa8db1d6b97ce63d4e2ef17
4
+ data.tar.gz: 37d7a7c0e1109f138a0e9860dd956002b6b68de6eb6b54cac501b62783b01bff
5
5
  SHA512:
6
- metadata.gz: 30e9043ea80059f42b536998decf73e7b672a54da0724a139dab572f41460118b1635f0ad00f30ef22d8c4825b1abf8d29cd49edc4cd6761fae4bd4787371f57
7
- data.tar.gz: f66cdc23a9feb4143ef6bb7cba086872bc9c47be6ab2073795c3f40921affb56c432100ad4c82d6624e712d3704b3df93a8561a3ef971bddaaa19635638a989f
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, CONDITION_OF_EXECUTION
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
- `CONDITION_OF_EXECUTION` is a method which allows or denieds execution of query step.
90
- 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.
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PlainQuery
4
- VERSION = '0.2.0'.freeze
4
+ VERSION = '0.2.1'.freeze
5
5
  end
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.0
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-09-17 00:00:00.000000000 Z
11
+ date: 2022-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord