services 7.0.3 → 7.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/services/query.rb +30 -20
- data/lib/services/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: 6fe25182ce1c9112cb5038acb3c2b2142bb62e4cc92457d4db4da8ef5b0a323a
|
4
|
+
data.tar.gz: 395f8a026b22de6fa716faba2e336c75542f79b23fcc0c7c7ed6f8d8926a0008
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7dd47187a80a3f174d7699160c1e4ae0606fa145bbed2b07c8c363a8b4eebde80586031ee6035ee0b9637be33af3b560a8e29d20789ab7db5338f6487c152802
|
7
|
+
data.tar.gz: 938b7cc0457dbed15ef374b8ba9771c6f91de395d095f8864ba7959f848731d5d60262f4c2110809eecb741eb8506afb6f7e658ba449e74b197dfd770d0062a6
|
data/lib/services/query.rb
CHANGED
@@ -2,6 +2,10 @@ module Services
|
|
2
2
|
class Query
|
3
3
|
include ObjectClass
|
4
4
|
|
5
|
+
COMMA_REGEX = /\s*,\s*/
|
6
|
+
TABLE_NAME_REGEX = /\A([A-Za-z0-9_]+)\./
|
7
|
+
CREATED_BEFORE_AFTER_REGEX = /\Acreated_(before|after)\z/
|
8
|
+
|
5
9
|
class << self
|
6
10
|
delegate :call, to: :new
|
7
11
|
|
@@ -33,10 +37,12 @@ module Services
|
|
33
37
|
conditions[:order] = object_table_id
|
34
38
|
end
|
35
39
|
|
36
|
-
scope = conditions.delete(:scope).try(:dup) || object_class.
|
37
|
-
|
40
|
+
scope = conditions.delete(:scope).try(:dup) || object_class.all
|
41
|
+
if ids.any?
|
42
|
+
scope = scope.where(object_table_id => ids)
|
43
|
+
end
|
38
44
|
|
39
|
-
|
45
|
+
if conditions.any?
|
40
46
|
self.class.object_to_id_class_names.each do |class_name|
|
41
47
|
if object_or_objects = conditions.delete(class_name)
|
42
48
|
ids = case object_or_objects
|
@@ -68,32 +74,36 @@ module Services
|
|
68
74
|
case k
|
69
75
|
when :id_not
|
70
76
|
scope = scope.where.not(id: v)
|
71
|
-
when
|
77
|
+
when CREATED_BEFORE_AFTER_REGEX
|
72
78
|
operator = $1 == 'before' ? '<' : '>'
|
73
79
|
scope = scope.where("#{object_class.table_name}.created_at #{operator} ?", v)
|
74
80
|
when :order
|
75
81
|
next unless v
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
table_name
|
81
|
-
unless table_name == object_class.table_name
|
82
|
+
|
83
|
+
order = v.split(COMMA_REGEX).map do |order_part|
|
84
|
+
table_name = order_part[TABLE_NAME_REGEX, 1]
|
85
|
+
case
|
86
|
+
when table_name && table_name != object_class.table_name
|
82
87
|
unless reflection = object_class.reflections.values.detect { |reflection| reflection.table_name == table_name }
|
83
88
|
fail "Reflection on class #{object_class} with table name #{table_name} not found."
|
84
89
|
end
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
join_conditions
|
90
|
+
|
91
|
+
if ActiveRecord::VERSION::MAJOR >= 5
|
92
|
+
scope = scope.left_outer_joins(reflection.name)
|
93
|
+
else
|
94
|
+
join_conditions = "LEFT OUTER JOIN #{table_name} ON #{table_name}.#{reflection.foreign_key} = #{object_class.table_name}.id"
|
95
|
+
if reflection.type
|
96
|
+
join_conditions << " AND #{table_name}.#{reflection.type} = '#{object_class}'"
|
97
|
+
end
|
98
|
+
scope = scope.joins(join_conditions)
|
90
99
|
end
|
91
|
-
|
100
|
+
|
101
|
+
order = order_part
|
102
|
+
when !table_name
|
103
|
+
order = "#{object_class.table_name}.#{order_part}"
|
92
104
|
end
|
93
|
-
|
94
|
-
|
95
|
-
order = "#{object_class.table_name}.#{v}"
|
96
|
-
end
|
105
|
+
end.join(', ')
|
106
|
+
|
97
107
|
scope = scope.order(order)
|
98
108
|
when :limit
|
99
109
|
scope = scope.limit(v)
|
data/lib/services/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: services
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 7.0
|
4
|
+
version: 7.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Manuel Meurer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-08-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|