hightop 0.1.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -2
- data/CHANGELOG.md +4 -0
- data/lib/hightop.rb +6 -10
- data/lib/hightop/version.rb +1 -1
- data/test/hightop_test.rb +6 -0
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b7e3f9ed74cce5d6a2e2a40f74634de04bcdcf8
|
4
|
+
data.tar.gz: a4b20f5a241a447bac6b3d1eefc3123d93d076e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a9fa28eac3b9273a8cb63f74031c1bfd6698dd409601ab4ccc8182b9eca4f8233e7e1d8de67053de8ae9a0bc621eee849f34e60addbba089a566ee698603eaf
|
7
|
+
data.tar.gz: 046cb949463896d1ee5637dcb58529c5d6a9742c8f868fc6a2d85d252d353c6ccff2c8d0dd03e65e715c51d7d2347aaba309e18d1010171ac1b53f659ababcb1
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/lib/hightop.rb
CHANGED
@@ -2,27 +2,23 @@ require "hightop/version"
|
|
2
2
|
require "active_record"
|
3
3
|
|
4
4
|
module Hightop
|
5
|
-
def top(column, limit = nil,
|
6
|
-
|
7
|
-
options = limit
|
8
|
-
limit = nil
|
9
|
-
end
|
10
|
-
|
11
|
-
distinct = options[:distinct] || options[:uniq]
|
5
|
+
def top(column, limit = nil, distinct: nil, uniq: nil, min: nil, nil: nil)
|
6
|
+
distinct ||= uniq
|
12
7
|
order_str = column.is_a?(Array) ? column.map(&:to_s).join(", ") : column
|
13
8
|
relation = group(column).order("count_#{distinct || 'all'} DESC, #{order_str}")
|
14
9
|
if limit
|
15
10
|
relation = relation.limit(limit)
|
16
11
|
end
|
17
12
|
|
18
|
-
|
13
|
+
# terribly named option
|
14
|
+
unless binding.local_variable_get(:nil)
|
19
15
|
(column.is_a?(Array) ? column : [column]).each do |c|
|
20
16
|
relation = relation.where("#{c} IS NOT NULL")
|
21
17
|
end
|
22
18
|
end
|
23
19
|
|
24
|
-
if
|
25
|
-
relation = relation.having("COUNT(#{distinct ? "DISTINCT #{distinct}" : '*'}) >= #{
|
20
|
+
if min
|
21
|
+
relation = relation.having("COUNT(#{distinct ? "DISTINCT #{distinct}" : '*'}) >= #{min.to_i}")
|
26
22
|
end
|
27
23
|
|
28
24
|
if distinct
|
data/lib/hightop/version.rb
CHANGED
data/test/hightop_test.rb
CHANGED
@@ -101,6 +101,12 @@ class TestHightop < Minitest::Test
|
|
101
101
|
assert_equal expected, Visit.top(:city, min: 2, distinct: :user_id)
|
102
102
|
end
|
103
103
|
|
104
|
+
def test_bad_argument
|
105
|
+
assert_raises(ArgumentError) do
|
106
|
+
Visit.top(:city, boom: true)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
104
110
|
def create_city(city, count = 1)
|
105
111
|
create({city: city}, count)
|
106
112
|
end
|
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.
|
4
|
+
version: 0.2.0
|
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: 2017-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -119,11 +119,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
119
119
|
version: '0'
|
120
120
|
requirements: []
|
121
121
|
rubyforge_project:
|
122
|
-
rubygems_version: 2.
|
122
|
+
rubygems_version: 2.6.8
|
123
123
|
signing_key:
|
124
124
|
specification_version: 4
|
125
125
|
summary: A nice shortcut for group count queries
|
126
126
|
test_files:
|
127
127
|
- test/hightop_test.rb
|
128
128
|
- test/test_helper.rb
|
129
|
-
has_rdoc:
|