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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f4ba31679cb700fe46cd163fd984d7243e2478650cfa1bcb0c59bdf26badbf28
4
- data.tar.gz: dcb3badaefe09c30cf07ac866b5c441da841f83663c408d53df0c76a9904ec79
3
+ metadata.gz: 0ec2c9fc6cd987c7aed6c82a1aa34e8d16f4948394f167b53209278eff78805a
4
+ data.tar.gz: 9f09eadc6a1b4294b846a5570491a660f1fe6cffed4b294035ec86381ea1af33
5
5
  SHA512:
6
- metadata.gz: a3388b6c8219826576969e9b3165fffedf629eeb116d7ddb96da84cd1801e24c9903eb16ac8c32feb3dca638222f066e7f3d9c4b19a6e5bf8a79e325b807e93b
7
- data.tar.gz: b80ae9265e8aaefc22c57bafe90c17c7923b1b9c497531832a8c46a803eeb759cfc938422b8eb14ffa543540c15705898efc3def86e65575b04d4124c7f08adc
6
+ metadata.gz: 9ccb8ca1e97cc909828425802a9f1ffdba7e291aeabdba29fa5489c4803898a0147f0521b7235a82f2b23e3b139aa2eaf1170aed4ce8142f07aead9b8beb9cea
7
+ data.tar.gz: 26a8beb63cba18b20ccecb7894ba0f9c4a260065366d51fdad3d351436a2415734a09695b7402298f0f431976d152baf02475ad60afa1027209b9c522ca9dffe
@@ -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] = object_table_id unless special_conditions.has_key?(: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
- order = case v
68
- when 'random' then 'RANDOM()'
69
- when /\./ then v
70
- else "#{object_class.table_name}.#{v}"
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
@@ -1,3 +1,3 @@
1
1
  module Services
2
- VERSION = '6.0.3'.freeze
2
+ VERSION = '6.0.4'.freeze
3
3
  end
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.3
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: 2017-12-29 00:00:00.000000000 Z
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.4
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