hightop 0.1.2 → 0.1.3
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 +10 -0
- data/CHANGELOG.md +5 -1
- data/Gemfile +1 -1
- data/README.md +2 -0
- data/Rakefile +1 -1
- data/hightop.gemspec +4 -4
- data/lib/hightop.rb +2 -4
- data/lib/hightop/version.rb +1 -1
- data/test/hightop_test.rb +4 -6
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8123384a25f9687e070f4ee86677c1afc5060a1f
|
4
|
+
data.tar.gz: 3b3776446331302a639859ba54d12cfa77b450aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 51c28c43483583167675608a90698f5a3e5b2b7bcf362278ab89b63a56c065d7adad51993e111005201b70e2e63ae5f7570db5e5eb1ce39cec1df085f32952ad
|
7
|
+
data.tar.gz: 191b537904fcb730a4e313714f9168b475e8017a791131e60c9173ea4ec5c7a5e817e73324af5388c0161a106eb336e20da3b4a8e6074f2ed5bcc81db0d2dd8c
|
data/.travis.yml
ADDED
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
data/Rakefile
CHANGED
data/hightop.gemspec
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
lib = File.expand_path(
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require
|
4
|
+
require "hightop/version"
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "hightop"
|
8
8
|
spec.version = Hightop::VERSION
|
9
9
|
spec.authors = ["Andrew Kane"]
|
10
10
|
spec.email = ["andrew@chartkick.com"]
|
11
|
-
spec.summary =
|
12
|
-
spec.description =
|
11
|
+
spec.summary = "A nice shortcut for group count queries"
|
12
|
+
spec.description = "A nice shortcut for group count queries"
|
13
13
|
spec.homepage = "https://github.com/ankane/hightop"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
data/lib/hightop.rb
CHANGED
@@ -2,7 +2,6 @@ require "hightop/version"
|
|
2
2
|
require "active_record"
|
3
3
|
|
4
4
|
module Hightop
|
5
|
-
|
6
5
|
def top(column, limit = nil, options = {})
|
7
6
|
if limit.is_a?(Hash)
|
8
7
|
options = limit
|
@@ -10,7 +9,7 @@ module Hightop
|
|
10
9
|
end
|
11
10
|
|
12
11
|
order_str = column.is_a?(Array) ? column.map(&:to_s).join(", ") : column
|
13
|
-
relation = group(column).order("count_#{options[:uniq] ||
|
12
|
+
relation = group(column).order("count_#{options[:uniq] || 'all'} DESC, #{order_str}")
|
14
13
|
if limit
|
15
14
|
relation = relation.limit(limit)
|
16
15
|
end
|
@@ -22,7 +21,7 @@ module Hightop
|
|
22
21
|
end
|
23
22
|
|
24
23
|
if options[:min]
|
25
|
-
relation = relation.having("COUNT(*) >= #{options[:min].to_i}")
|
24
|
+
relation = relation.having("COUNT(#{options[:uniq] ? "DISTINCT #{options[:uniq]}" : '*'}) >= #{options[:min].to_i}")
|
26
25
|
end
|
27
26
|
|
28
27
|
if options[:uniq]
|
@@ -31,7 +30,6 @@ module Hightop
|
|
31
30
|
relation.count
|
32
31
|
end
|
33
32
|
end
|
34
|
-
|
35
33
|
end
|
36
34
|
|
37
35
|
ActiveRecord::Base.send :extend, Hightop
|
data/lib/hightop/version.rb
CHANGED
data/test/hightop_test.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require_relative "test_helper"
|
2
2
|
|
3
3
|
class TestHightop < Minitest::Test
|
4
|
-
|
5
4
|
def setup
|
6
5
|
Visit.delete_all
|
7
6
|
end
|
@@ -32,7 +31,7 @@ class TestHightop < Minitest::Test
|
|
32
31
|
create_city("San Francisco", 3)
|
33
32
|
create_city(nil, 2)
|
34
33
|
expected = {
|
35
|
-
"San Francisco" => 3
|
34
|
+
"San Francisco" => 3
|
36
35
|
}
|
37
36
|
assert_equal expected, Visit.top(:city)
|
38
37
|
end
|
@@ -64,8 +63,8 @@ class TestHightop < Minitest::Test
|
|
64
63
|
end
|
65
64
|
|
66
65
|
def test_uniq
|
67
|
-
create(
|
68
|
-
create(
|
66
|
+
create(city: "San Francisco", user_id: 1)
|
67
|
+
create(city: "San Francisco", user_id: 1)
|
69
68
|
expected = {
|
70
69
|
"San Francisco" => 1
|
71
70
|
}
|
@@ -86,7 +85,6 @@ class TestHightop < Minitest::Test
|
|
86
85
|
end
|
87
86
|
|
88
87
|
def create(attributes, count = 1)
|
89
|
-
count.times{ Visit.create!(attributes) }
|
88
|
+
count.times { Visit.create!(attributes) }
|
90
89
|
end
|
91
|
-
|
92
90
|
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.1.
|
4
|
+
version: 0.1.3
|
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: 2015-06-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -88,6 +88,7 @@ extensions: []
|
|
88
88
|
extra_rdoc_files: []
|
89
89
|
files:
|
90
90
|
- ".gitignore"
|
91
|
+
- ".travis.yml"
|
91
92
|
- CHANGELOG.md
|
92
93
|
- Gemfile
|
93
94
|
- LICENSE.txt
|
@@ -118,10 +119,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
119
|
version: '0'
|
119
120
|
requirements: []
|
120
121
|
rubyforge_project:
|
121
|
-
rubygems_version: 2.
|
122
|
+
rubygems_version: 2.4.5
|
122
123
|
signing_key:
|
123
124
|
specification_version: 4
|
124
125
|
summary: A nice shortcut for group count queries
|
125
126
|
test_files:
|
126
127
|
- test/hightop_test.rb
|
127
128
|
- test/test_helper.rb
|
129
|
+
has_rdoc:
|