Permalink
Browse files

First commit

  • Loading branch information...
0 parents commit d8b982e28d7cf64878f33554094294cc9e17d8be @ankane committed May 11, 2014
Showing with 130 additions and 0 deletions.
  1. +22 −0 .gitignore
  2. +4 −0 Gemfile
  3. +22 −0 LICENSE.txt
  4. +42 −0 README.md
  5. +2 −0 Rakefile
  6. +23 −0 hightop.gemspec
  7. +12 −0 lib/hightop.rb
  8. +3 −0 lib/hightop/version.rb
@@ -0,0 +1,22 @@
+*.gem
+*.rbc
+.bundle
+.config
+.yardoc
+Gemfile.lock
+InstalledFiles
+_yardoc
+coverage
+doc/
+lib/bundler/man
+pkg
+rdoc
+spec/reports
+test/tmp
+test/version_tmp
+tmp
+*.bundle
+*.so
+*.o
+*.a
+mkmf.log
@@ -0,0 +1,4 @@
+source 'https://rubygems.org'
+
+# Specify your gem's dependencies in hightop.gemspec
+gemspec
@@ -0,0 +1,22 @@
+Copyright (c) 2014 Andrew Kane
+
+MIT License
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,42 @@
+# Hightop
+
+Super convenient group count
+
+```ruby
+User.top(:gender)
+```
+
+instead of
+
+```ruby
+User.group(:gender).where("gender IS NOT NULL").order("count_all DESC, gender").count
+```
+
+Limit the results
+
+```ruby
+Visit.limit(10).top(:referring_domain)
+```
+
+## Installation
+
+Add this line to your application’s Gemfile:
+
+```ruby
+gem 'hightop'
+```
+
+And then execute:
+
+```sh
+bundle
+```
+
+## Contributing
+
+Everyone is encouraged to help improve this project. Here are a few ways you can help:
+
+- [Report bugs](https://github.com/ankane/hightop/issues)
+- Fix bugs and [submit pull requests](https://github.com/ankane/hightop/pulls)
+- Write, clarify, or fix documentation
+- Suggest or add new features
@@ -0,0 +1,2 @@
+require "bundler/gem_tasks"
+
@@ -0,0 +1,23 @@
+# coding: utf-8
+lib = File.expand_path('../lib', __FILE__)
+$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
+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{Super convenient group count}
+ spec.description = %q{Super convenient group count}
+ spec.homepage = "https://github.com/ankane/hightop"
+ spec.license = "MIT"
+
+ spec.files = `git ls-files -z`.split("\x0")
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
+ spec.require_paths = ["lib"]
+
+ spec.add_development_dependency "bundler", "~> 1.6"
+ spec.add_development_dependency "rake"
+end
@@ -0,0 +1,12 @@
+require "hightop/version"
+
+module Hightop
+
+ def top(column)
+ column = connection.quote_table_name(column)
+ group(column).where("#{column} IS NOT NULL").order("count_all DESC, #{column}").count
+ end
+
+end
+
+ActiveRecord::Base.send :extend, Hightop
@@ -0,0 +1,3 @@
+module Hightop
+ VERSION = "0.0.1"
+end

0 comments on commit d8b982e

Please sign in to comment.