hightop 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -1
- data/lib/hightop.rb +1 -0
- data/lib/hightop/kicks.rb +16 -4
- data/lib/hightop/mongoid.rb +6 -2
- data/lib/hightop/utils.rb +21 -0
- data/lib/hightop/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e986b06b74104ea5fb99fe92abdb061eab4cc225ba9fa4f34216eadcd704e556
|
4
|
+
data.tar.gz: 5ca8954b8ce39c1212e0bc0b651e22450ff26b17795665b561cc7e4bbb134067
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e9d93d7b9edcce9dcfb6f3b7912ef3252454731bcc68d45cc9ff391df854a6fe49e5d7ca269780e55e98cf1481a17ef3472427de69694d6098cfdcacf9e61c7d
|
7
|
+
data.tar.gz: cd86dfd59b77d39482d06d0a6e9f59869ca15eaab6eef6e5cc62f754ad9d3addd781e21749a192a181385620b2508b520ee22da1f2c397566ac82159778a65d2
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,11 @@
|
|
1
|
+
## 0.2.4 (2020-09-07)
|
2
|
+
|
3
|
+
- Added warning for non-attribute argument
|
4
|
+
- Added deprecation warning for `uniq`
|
5
|
+
|
1
6
|
## 0.2.3 (2020-06-18)
|
2
7
|
|
3
|
-
- Dropped support for
|
8
|
+
- Dropped support for Active Record 4.2 and Ruby 2.3
|
4
9
|
- Fixed deprecation warning in Ruby 2.7
|
5
10
|
|
6
11
|
## 0.2.2 (2019-08-12)
|
data/lib/hightop.rb
CHANGED
data/lib/hightop/kicks.rb
CHANGED
@@ -1,22 +1,34 @@
|
|
1
1
|
module Hightop
|
2
2
|
module Kicks
|
3
3
|
def top(column, limit = nil, distinct: nil, uniq: nil, min: nil, nil: nil)
|
4
|
+
warn "[hightop] uniq is deprecated. Use distinct instead" if uniq
|
5
|
+
|
6
|
+
columns = column.is_a?(Array) ? column : [column]
|
7
|
+
columns.each { |c| Utils.validate_column(c) }
|
8
|
+
|
4
9
|
distinct ||= uniq
|
5
|
-
|
6
|
-
|
10
|
+
Utils.validate_column(distinct) if distinct
|
11
|
+
|
12
|
+
relation = group(*columns).order("1 DESC", *columns)
|
7
13
|
if limit
|
8
14
|
relation = relation.limit(limit)
|
9
15
|
end
|
10
16
|
|
11
17
|
# terribly named option
|
12
18
|
unless binding.local_variable_get(:nil)
|
13
|
-
|
19
|
+
columns.each do |c|
|
20
|
+
c = Utils.resolve_column(self, c)
|
14
21
|
relation = relation.where("#{c} IS NOT NULL")
|
15
22
|
end
|
16
23
|
end
|
17
24
|
|
18
25
|
if min
|
19
|
-
|
26
|
+
if distinct
|
27
|
+
d = Utils.resolve_column(self, distinct)
|
28
|
+
relation = relation.having("COUNT(DISTINCT #{d}) >= #{min.to_i}")
|
29
|
+
else
|
30
|
+
relation = relation.having("COUNT(*) >= #{min.to_i}")
|
31
|
+
end
|
20
32
|
end
|
21
33
|
|
22
34
|
if distinct
|
data/lib/hightop/mongoid.rb
CHANGED
@@ -3,19 +3,23 @@ module Hightop
|
|
3
3
|
# super helpful article
|
4
4
|
# https://maximomussini.com/posts/mongoid-aggregation-dsl/
|
5
5
|
def top(column, limit = nil, distinct: nil, uniq: nil, min: nil, nil: nil)
|
6
|
+
warn "[hightop] uniq is deprecated. Use distinct instead" if uniq
|
7
|
+
|
8
|
+
columns = column.is_a?(Array) ? column : [column]
|
9
|
+
|
6
10
|
distinct ||= uniq
|
7
11
|
|
8
12
|
relation = all
|
9
13
|
|
10
14
|
# terribly named option
|
11
15
|
unless binding.local_variable_get(:nil)
|
12
|
-
|
16
|
+
columns.each do |c|
|
13
17
|
relation = relation.and(c.ne => nil)
|
14
18
|
end
|
15
19
|
end
|
16
20
|
|
17
21
|
ids = {}
|
18
|
-
|
22
|
+
columns.each_with_index do |c, i|
|
19
23
|
ids["c#{i}"] = "$#{c}"
|
20
24
|
end
|
21
25
|
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Hightop
|
2
|
+
module Utils
|
3
|
+
class << self
|
4
|
+
# basic version of Active Record disallow_raw_sql!
|
5
|
+
# symbol = column (safe), Arel node = SQL (safe), other = untrusted
|
6
|
+
# matches table.column and column
|
7
|
+
def validate_column(column)
|
8
|
+
unless column.is_a?(Symbol) || column.is_a?(Arel::Nodes::SqlLiteral) || /\A\w+(\.\w+)?\z/i.match(column.to_s)
|
9
|
+
warn "[hightop] Non-attribute argument: #{column}. Use Arel.sql() for known-safe values. This will raise an error in Hightop 0.3.0"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# resolves eagerly
|
14
|
+
def resolve_column(relation, column)
|
15
|
+
node = relation.send(:relation).send(:arel_columns, [column]).first
|
16
|
+
node = Arel::Nodes::SqlLiteral.new(node) if node.is_a?(String)
|
17
|
+
relation.connection.visitor.accept(node, Arel::Collectors::SQLString.new).value
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/hightop/version.rb
CHANGED
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.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-09-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -93,6 +93,7 @@ files:
|
|
93
93
|
- lib/hightop/enumerable.rb
|
94
94
|
- lib/hightop/kicks.rb
|
95
95
|
- lib/hightop/mongoid.rb
|
96
|
+
- lib/hightop/utils.rb
|
96
97
|
- lib/hightop/version.rb
|
97
98
|
homepage: https://github.com/ankane/hightop
|
98
99
|
licenses:
|