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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 19538edc7ac8f8cc81df7ad682c47ec6dfe0d38e
4
- data.tar.gz: 2f2bb4d909ead9b64fa293627a784c5adeaadd2d
3
+ metadata.gz: 0b7e3f9ed74cce5d6a2e2a40f74634de04bcdcf8
4
+ data.tar.gz: a4b20f5a241a447bac6b3d1eefc3123d93d076e2
5
5
  SHA512:
6
- metadata.gz: ac01a53983e69a760c745bcddd99287774ae73d7b743dcf4be327b252c0524e3147b6e815a1560b735f6cdf2252d651402ea9b775468bd93300d056fdcea18d3
7
- data.tar.gz: 37252ef2688c355c2aa327f36fd5025c7809986abfc256bb4f8ea0df48442c8add698d944261b2a0ee0d16ee5c3d52b352023ad7c334a6ec39fe80e80a3922f0
6
+ metadata.gz: 8a9fa28eac3b9273a8cb63f74031c1bfd6698dd409601ab4ccc8182b9eca4f8233e7e1d8de67053de8ae9a0bc621eee849f34e60addbba089a566ee698603eaf
7
+ data.tar.gz: 046cb949463896d1ee5637dcb58529c5d6a9742c8f868fc6a2d85d252d353c6ccff2c8d0dd03e65e715c51d7d2347aaba309e18d1010171ac1b53f659ababcb1
@@ -1,6 +1,5 @@
1
1
  language: ruby
2
- rvm:
3
- - 2.1
2
+ rvm: 2.2.5
4
3
  gemfile:
5
4
  - Gemfile
6
5
  sudo: false
@@ -1,3 +1,7 @@
1
+ ## 0.2.0
2
+
3
+ - Use keyword arguments
4
+
1
5
  ## 0.1.4
2
6
 
3
7
  - Added `distinct` option to replace `uniq`
@@ -2,27 +2,23 @@ require "hightop/version"
2
2
  require "active_record"
3
3
 
4
4
  module Hightop
5
- def top(column, limit = nil, options = {})
6
- if limit.is_a?(Hash)
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
- unless options[:nil]
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 options[:min]
25
- relation = relation.having("COUNT(#{distinct ? "DISTINCT #{distinct}" : '*'}) >= #{options[:min].to_i}")
20
+ if min
21
+ relation = relation.having("COUNT(#{distinct ? "DISTINCT #{distinct}" : '*'}) >= #{min.to_i}")
26
22
  end
27
23
 
28
24
  if distinct
@@ -1,3 +1,3 @@
1
1
  module Hightop
2
- VERSION = "0.1.4"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -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.1.4
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: 2016-02-04 00:00:00.000000000 Z
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.4.5.1
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: