Permalink
Browse files

Updated style

  • Loading branch information...
1 parent 2b5c90d commit c9bbfddd63af32d3736bb842d45754e0c5cc1466 @ankane committed Mar 11, 2015
Showing with 12 additions and 16 deletions.
  1. +1 −1 Gemfile
  2. +1 −1 Rakefile
  3. +4 −4 hightop.gemspec
  4. +2 −4 lib/hightop.rb
  5. +4 −6 test/hightop_test.rb
View
@@ -1,4 +1,4 @@
-source 'https://rubygems.org'
+source "https://rubygems.org"
# Specify your gem's dependencies in hightop.gemspec
gemspec
View
@@ -1,7 +1,7 @@
require "bundler/gem_tasks"
require "rake/testtask"
-task :default => :test
+task default: :test
Rake::TestTask.new do |t|
t.libs << "test"
t.pattern = "test/**/*_test.rb"
View
@@ -1,15 +1,15 @@
# coding: utf-8
-lib = File.expand_path('../lib', __FILE__)
+lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
-require 'hightop/version'
+require "hightop/version"
Gem::Specification.new do |spec|
spec.name = "hightop"
spec.version = Hightop::VERSION
spec.authors = ["Andrew Kane"]
spec.email = ["andrew@chartkick.com"]
- spec.summary = %q{A nice shortcut for group count queries}
- spec.description = %q{A nice shortcut for group count queries}
+ spec.summary = "A nice shortcut for group count queries"
+ spec.description = "A nice shortcut for group count queries"
spec.homepage = "https://github.com/ankane/hightop"
spec.license = "MIT"
View
@@ -2,15 +2,14 @@
require "active_record"
module Hightop
-
def top(column, limit = nil, options = {})
if limit.is_a?(Hash)
options = limit
limit = nil
end
order_str = column.is_a?(Array) ? column.map(&:to_s).join(", ") : column
- relation = group(column).order("count_#{options[:uniq] || "all"} DESC, #{order_str}")
+ relation = group(column).order("count_#{options[:uniq] || 'all'} DESC, #{order_str}")
if limit
relation = relation.limit(limit)
end
@@ -22,7 +21,7 @@ def top(column, limit = nil, options = {})
end
if options[:min]
- relation = relation.having("COUNT(#{options[:uniq] ? "DISTINCT #{options[:uniq]}" : "*"}) >= #{options[:min].to_i}")
+ relation = relation.having("COUNT(#{options[:uniq] ? "DISTINCT #{options[:uniq]}" : '*'}) >= #{options[:min].to_i}")
end
if options[:uniq]
@@ -31,7 +30,6 @@ def top(column, limit = nil, options = {})
relation.count
end
end
-
end
ActiveRecord::Base.send :extend, Hightop
View
@@ -1,7 +1,6 @@
require_relative "test_helper"
class TestHightop < Minitest::Test
-
def setup
Visit.delete_all
end
@@ -32,7 +31,7 @@ def test_nil_values
create_city("San Francisco", 3)
create_city(nil, 2)
expected = {
- "San Francisco" => 3,
+ "San Francisco" => 3
}
assert_equal expected, Visit.top(:city)
end
@@ -64,8 +63,8 @@ def test_expressions
end
def test_uniq
- create({city: "San Francisco", user_id: 1})
- create({city: "San Francisco", user_id: 1})
+ create(city: "San Francisco", user_id: 1)
+ create(city: "San Francisco", user_id: 1)
expected = {
"San Francisco" => 1
}
@@ -86,7 +85,6 @@ def create_city(city, count = 1)
end
def create(attributes, count = 1)
- count.times{ Visit.create!(attributes) }
+ count.times { Visit.create!(attributes) }
end
-
end

0 comments on commit c9bbfdd

Please sign in to comment.