hightop 0.1.2 → 0.1.3

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: 7afed0619ef7e10ad7396edd82f1b7ee4fd76bbd
4
- data.tar.gz: a490f3b11648fc044a1f1e0b9b52f7686efe7638
3
+ metadata.gz: 8123384a25f9687e070f4ee86677c1afc5060a1f
4
+ data.tar.gz: 3b3776446331302a639859ba54d12cfa77b450aa
5
5
  SHA512:
6
- metadata.gz: 8df32f44bc3eb512189840d6fb28b65af553aed3ad946de6e848975f5ad4faf052ef6d95a873217dafdd8ebde3f566eebf9884e3a303adc185746bcd89319315
7
- data.tar.gz: 53a8a14e86db5f6ded22ef82e8cfea1c52437aaca8ca6219f842b5060281a792d87d1ab52fc1ec9005170a4281c59ec3a9958cd84922e5bc5f8acae4a81c9436
6
+ metadata.gz: 51c28c43483583167675608a90698f5a3e5b2b7bcf362278ab89b63a56c065d7adad51993e111005201b70e2e63ae5f7570db5e5eb1ce39cec1df085f32952ad
7
+ data.tar.gz: 191b537904fcb730a4e313714f9168b475e8017a791131e60c9173ea4ec5c7a5e817e73324af5388c0161a106eb336e20da3b4a8e6074f2ed5bcc81db0d2dd8c
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1
4
+ gemfile:
5
+ - Gemfile
6
+ script: bundle exec rake test
7
+ notifications:
8
+ email:
9
+ on_success: never
10
+ on_failure: change
data/CHANGELOG.md CHANGED
@@ -1,4 +1,8 @@
1
- ## 0.1.2 [unreleased]
1
+ ## 0.1.3
2
+
3
+ - Fixed `min` option with `uniq`
4
+
5
+ ## 0.1.2
2
6
 
3
7
  - Added `min` option
4
8
 
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in hightop.gemspec
4
4
  gemspec
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  A nice shortcut for group count queries
4
4
 
5
+ [![Build Status](https://travis-ci.org/ankane/hightop.svg)](https://travis-ci.org/ankane/hightop)
6
+
5
7
  ```ruby
6
8
  Visit.top(:browser)
7
9
  ```
data/Rakefile CHANGED
@@ -1,7 +1,7 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rake/testtask"
3
3
 
4
- task :default => :test
4
+ task default: :test
5
5
  Rake::TestTask.new do |t|
6
6
  t.libs << "test"
7
7
  t.pattern = "test/**/*_test.rb"
data/hightop.gemspec CHANGED
@@ -1,15 +1,15 @@
1
1
  # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
2
+ lib = File.expand_path("../lib", __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'hightop/version'
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 = %q{A nice shortcut for group count queries}
12
- spec.description = %q{A nice shortcut for group count queries}
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] || "all"} DESC, #{order_str}")
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
@@ -1,3 +1,3 @@
1
1
  module Hightop
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
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({city: "San Francisco", user_id: 1})
68
- create({city: "San Francisco", user_id: 1})
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.2
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: 2014-11-06 00:00:00.000000000 Z
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.2.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: