services 6.0.3 → 6.0.4
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 +21 -5
- data/lib/services/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ec2c9fc6cd987c7aed6c82a1aa34e8d16f4948394f167b53209278eff78805a
|
4
|
+
data.tar.gz: 9f09eadc6a1b4294b846a5570491a660f1fe6cffed4b294035ec86381ea1af33
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ccb8ca1e97cc909828425802a9f1ffdba7e291aeabdba29fa5489c4803898a0147f0521b7235a82f2b23e3b139aa2eaf1170aed4ce8142f07aead9b8beb9cea
|
7
|
+
data.tar.gz: 26a8beb63cba18b20ccecb7894ba0f9c4a260065366d51fdad3d351436a2415734a09695b7402298f0f431976d152baf02475ad60afa1027209b9c522ca9dffe
|
data/lib/services/query.rb
CHANGED
@@ -30,7 +30,7 @@ module Services
|
|
30
30
|
object_table_id = "#{object_class.table_name}.id"
|
31
31
|
|
32
32
|
special_conditions = conditions.extract!(:id_not, :order, :limit, :page, :per_page)
|
33
|
-
special_conditions[:order]
|
33
|
+
special_conditions[:order] ||= object_table_id
|
34
34
|
|
35
35
|
scope = conditions.delete(:scope).try(:dup) || object_class.public_send(ActiveRecord::VERSION::MAJOR == 3 ? :scoped : :all)
|
36
36
|
scope = scope.where(object_table_id => ids) unless ids.empty?
|
@@ -64,10 +64,26 @@ module Services
|
|
64
64
|
scope = scope.where.not(id: v)
|
65
65
|
when :order
|
66
66
|
next unless v
|
67
|
-
|
68
|
-
when 'random'
|
69
|
-
|
70
|
-
|
67
|
+
case v
|
68
|
+
when 'random'
|
69
|
+
order = 'RANDOM()'
|
70
|
+
when /\A([A-Za-z0-9_]+)\./
|
71
|
+
table_name = $1
|
72
|
+
unless table_name == object_class.table_name
|
73
|
+
unless reflection = object_class.reflections.values.detect { |reflection| reflection.table_name == table_name }
|
74
|
+
fail "Reflection on class #{object_class} with table name #{table_name} not found."
|
75
|
+
end
|
76
|
+
# TODO: In Rails 5, we can use #left_outer_joins
|
77
|
+
# http://blog.bigbinary.com/2016/03/24/support-for-left-outer-joins-in-rails-5.html
|
78
|
+
join_conditions = "LEFT OUTER JOIN #{table_name} ON #{table_name}.#{reflection.foreign_key} = #{object_class.table_name}.id"
|
79
|
+
if reflection.type
|
80
|
+
join_conditions << " AND #{table_name}.#{reflection.type} = '#{object_class}'"
|
81
|
+
end
|
82
|
+
scope = scope.joins(join_conditions)
|
83
|
+
end
|
84
|
+
order = v
|
85
|
+
else
|
86
|
+
order = "#{object_class.table_name}.#{v}"
|
71
87
|
end
|
72
88
|
scope = scope.order(order)
|
73
89
|
when :limit
|
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: 6.0.
|
4
|
+
version: 6.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Manuel Meurer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-06-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -246,7 +246,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
246
246
|
version: '0'
|
247
247
|
requirements: []
|
248
248
|
rubyforge_project:
|
249
|
-
rubygems_version: 2.7.
|
249
|
+
rubygems_version: 2.7.6
|
250
250
|
signing_key:
|
251
251
|
specification_version: 4
|
252
252
|
summary: A nifty service layer for your Rails app
|