postgres_ext 2.1.1 → 2.1.2
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
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f41de74b7eea3b27f6770cb352ba70497d94513d
|
4
|
+
data.tar.gz: 3e9cf324c7a635ac338fd5af691909ed13f1f02e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5843378f753e2755c7c8459d89b580d10089d564b18ee390e349a3590efb0260bb12f6e9ef784bb02ef2514389351b303d867dbe7de4de859ac16ffdd88925ab
|
7
|
+
data.tar.gz: cf54fb746947851736f94fbf0e543eae772dfa7e85094c343853f12086c0c3c2c906ae2f15b4412de00fed0f1c749279a51a15a004fe8c5f07de9bdbadc05092
|
@@ -130,25 +130,27 @@ module ActiveRecord
|
|
130
130
|
end
|
131
131
|
|
132
132
|
def build_rank(arel, ranks)
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
133
|
+
unless arel.projections.count == 1 && Arel::Nodes::Count === arel.projections.first
|
134
|
+
rank_orders = ranks.uniq.reject(&:blank?).flat_map do |value|
|
135
|
+
case value
|
136
|
+
when :order
|
137
|
+
arel.orders
|
138
|
+
when Symbol
|
139
|
+
table[value].asc
|
140
|
+
when Hash
|
141
|
+
value.map { |field, dir| table[field].send(dir) }
|
142
|
+
else
|
143
|
+
Arel::Nodes::SqlLiteral.new value
|
144
|
+
end
|
143
145
|
end
|
144
|
-
end
|
145
146
|
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
147
|
+
unless rank_orders.blank?
|
148
|
+
rank_node = Arel::Nodes::SqlLiteral.new 'rank()'
|
149
|
+
window = Arel::Nodes::Window.new.order(rank_orders)
|
150
|
+
over_node = Arel::Nodes::Over.new rank_node, window
|
150
151
|
|
151
|
-
|
152
|
+
arel.project(over_node)
|
153
|
+
end
|
152
154
|
end
|
153
155
|
end
|
154
156
|
|
data/lib/postgres_ext/version.rb
CHANGED
@@ -40,5 +40,10 @@ describe 'Window functions' do
|
|
40
40
|
ranked_people[0].rank.should eq 1
|
41
41
|
ranked_people[1].rank.should eq 2
|
42
42
|
end
|
43
|
+
|
44
|
+
it 'does not apply the rank when performing a count' do
|
45
|
+
query = Person.ranked(lucky_number: :desc).count
|
46
|
+
query.should eq 0
|
47
|
+
end
|
43
48
|
end
|
44
49
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: postgres_ext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan McClain
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-09-
|
11
|
+
date: 2013-09-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|