hightop 0.1.3 → 0.1.4
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 +4 -4
- data/.travis.yml +2 -0
- data/CHANGELOG.md +4 -0
- data/README.md +1 -1
- data/lib/hightop.rb +10 -4
- data/lib/hightop/version.rb +1 -1
- data/test/hightop_test.rb +21 -0
- data/test/test_helper.rb +2 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19538edc7ac8f8cc81df7ad682c47ec6dfe0d38e
|
4
|
+
data.tar.gz: 2f2bb4d909ead9b64fa293627a784c5adeaadd2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ac01a53983e69a760c745bcddd99287774ae73d7b743dcf4be327b252c0524e3147b6e815a1560b735f6cdf2252d651402ea9b775468bd93300d056fdcea18d3
|
7
|
+
data.tar.gz: 37252ef2688c355c2aa327f36fd5025c7809986abfc256bb4f8ea0df48442c8add698d944261b2a0ee0d16ee5c3d52b352023ad7c334a6ec39fe80e80a3922f0
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
data/lib/hightop.rb
CHANGED
@@ -8,8 +8,9 @@ module Hightop
|
|
8
8
|
limit = nil
|
9
9
|
end
|
10
10
|
|
11
|
+
distinct = options[:distinct] || options[:uniq]
|
11
12
|
order_str = column.is_a?(Array) ? column.map(&:to_s).join(", ") : column
|
12
|
-
relation = group(column).order("count_#{
|
13
|
+
relation = group(column).order("count_#{distinct || 'all'} DESC, #{order_str}")
|
13
14
|
if limit
|
14
15
|
relation = relation.limit(limit)
|
15
16
|
end
|
@@ -21,11 +22,16 @@ module Hightop
|
|
21
22
|
end
|
22
23
|
|
23
24
|
if options[:min]
|
24
|
-
relation = relation.having("COUNT(#{
|
25
|
+
relation = relation.having("COUNT(#{distinct ? "DISTINCT #{distinct}" : '*'}) >= #{options[:min].to_i}")
|
25
26
|
end
|
26
27
|
|
27
|
-
if
|
28
|
-
relation.
|
28
|
+
if distinct
|
29
|
+
# since relation.respond_to?(:distinct) can't be used
|
30
|
+
if ActiveRecord::VERSION::MAJOR > 3
|
31
|
+
relation.distinct.count(distinct)
|
32
|
+
else
|
33
|
+
relation.uniq.count(distinct)
|
34
|
+
end
|
29
35
|
else
|
30
36
|
relation.count
|
31
37
|
end
|
data/lib/hightop/version.rb
CHANGED
data/test/hightop_test.rb
CHANGED
@@ -62,6 +62,15 @@ class TestHightop < Minitest::Test
|
|
62
62
|
assert_equal expected, Visit.top("LOWER(city)")
|
63
63
|
end
|
64
64
|
|
65
|
+
def test_distinct
|
66
|
+
create(city: "San Francisco", user_id: 1)
|
67
|
+
create(city: "San Francisco", user_id: 1)
|
68
|
+
expected = {
|
69
|
+
"San Francisco" => 1
|
70
|
+
}
|
71
|
+
assert_equal expected, Visit.top(:city, distinct: :user_id)
|
72
|
+
end
|
73
|
+
|
65
74
|
def test_uniq
|
66
75
|
create(city: "San Francisco", user_id: 1)
|
67
76
|
create(city: "San Francisco", user_id: 1)
|
@@ -80,6 +89,18 @@ class TestHightop < Minitest::Test
|
|
80
89
|
assert_equal expected, Visit.top(:city, min: 3)
|
81
90
|
end
|
82
91
|
|
92
|
+
def test_min_distinct
|
93
|
+
create(city: "San Francisco", user_id: 1)
|
94
|
+
create(city: "San Francisco", user_id: 1)
|
95
|
+
create(city: "San Francisco", user_id: 2)
|
96
|
+
create(city: "Chicago", user_id: 1)
|
97
|
+
create(city: "Chicago", user_id: 1)
|
98
|
+
expected = {
|
99
|
+
"San Francisco" => 2
|
100
|
+
}
|
101
|
+
assert_equal expected, Visit.top(:city, min: 2, distinct: :user_id)
|
102
|
+
end
|
103
|
+
|
83
104
|
def create_city(city, count = 1)
|
84
105
|
create({city: city}, count)
|
85
106
|
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hightop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-02-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -119,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
119
119
|
version: '0'
|
120
120
|
requirements: []
|
121
121
|
rubyforge_project:
|
122
|
-
rubygems_version: 2.4.5
|
122
|
+
rubygems_version: 2.4.5.1
|
123
123
|
signing_key:
|
124
124
|
specification_version: 4
|
125
125
|
summary: A nice shortcut for group count queries
|