hightop 0.0.3 → 0.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4f282f1928e3686e3b51e376e64c6caa727665dd
4
- data.tar.gz: 6c8614fee9db943bc7b0c6ad8c65576116ffc9f4
3
+ metadata.gz: 846b498786282576ab175fcf91cf24bfb9b86034
4
+ data.tar.gz: 8392b028241d3b03f59c62dec5b46f694cb8a33d
5
5
  SHA512:
6
- metadata.gz: b3c0135aebba9a186fdb2ab91e0f5d792c3c5d132305ae3b799c8a16b24a0239597b79d771d5e704e095602a0d048a084b41e2e2273b43c26a712435353534f5
7
- data.tar.gz: ce487ed0b6cef4b566a35ae92c83403ac597cd608a1a52222e1de99914e415505e1356da82aa88fd839e125ddba43a6ea3f3d3298687d58deb4c4c1da14235a8
6
+ metadata.gz: 8c1f11dd88fcc63423a3d927c13c2ab4ded446bb062dd104aa2f08d1580bd8dbca9907835aab2cc220e6e06c394747e2f76863c460f029626254d22345715952
7
+ data.tar.gz: debd4bc6b2a97302db73b08c313a30cfa6825509b838c7bc90acbebb62439518f003108df241b6a52621982f015c319084c17859d5c13afd0b8d248212048274
data/CHANGELOG.md ADDED
@@ -0,0 +1,12 @@
1
+ ## 0.0.4
2
+
3
+ - Added support for multiple groups
4
+ - Added `nil` option
5
+
6
+ ## 0.0.3
7
+
8
+ - Fixed escaping
9
+
10
+ ## 0.0.2
11
+
12
+ - Added `limit` parameter
data/README.md CHANGED
@@ -12,13 +12,25 @@ instead of
12
12
  Visit.group(:browser).where("browser IS NOT NULL").order("count_all DESC, browser").count
13
13
  ```
14
14
 
15
+ Be sure to [sanitize user input](http://rails-sqli.org/) like you must with `group`.
16
+
15
17
  Limit the results
16
18
 
17
19
  ```ruby
18
20
  Visit.top(:referring_domain, 10)
19
21
  ```
20
22
 
21
- Be sure to [sanitize user input](http://rails-sqli.org/) like you must with `group`.
23
+ Include nil values
24
+
25
+ ```ruby
26
+ Visit.top(:referring_domain, nil: true)
27
+ ```
28
+
29
+ Works with multiple groups
30
+
31
+ ```ruby
32
+ Visit.top([:city, :referring_domain])
33
+ ```
22
34
 
23
35
  ## Installation
24
36
 
@@ -1,3 +1,3 @@
1
1
  module Hightop
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/hightop.rb CHANGED
@@ -2,9 +2,22 @@ require "hightop/version"
2
2
 
3
3
  module Hightop
4
4
 
5
- def top(column, limit = nil)
6
- column = connection.quote_table_name(column) if column.is_a?(Symbol)
7
- group(column).where("#{column} IS NOT NULL").order("count_all DESC, #{column}").limit(limit).count
5
+ def top(column, limit = nil, options = {})
6
+ if limit.is_a?(Hash)
7
+ options = limit
8
+ limit = nil
9
+ end
10
+
11
+ order_str = column.is_a?(Array) ? column.map(&:to_s).join(", ") : column
12
+ relation = group(column).limit(limit).order("count_all DESC, #{order_str}")
13
+
14
+ unless options[:nil]
15
+ (column.is_a?(Array) ? column : [column]).each do |c|
16
+ relation = relation.where("#{c} IS NOT NULL")
17
+ end
18
+ end
19
+
20
+ relation.count
8
21
  end
9
22
 
10
23
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hightop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
@@ -46,6 +46,7 @@ extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
48
  - ".gitignore"
49
+ - CHANGELOG.md
49
50
  - Gemfile
50
51
  - LICENSE.txt
51
52
  - README.md