filterer 0.1.1 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/filterer/base.rb +17 -4
- data/lib/filterer/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed26d0a881cdb7a6d59cd1f624cd509c4e8a37ef
|
4
|
+
data.tar.gz: 8447cb8b4ae3e5b6ebb1466bef6e608c1058be63
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90ef47c106471c0af6d6b6d0983b33197c447584257c06b4635bf83298762c818439314677d508104828d01f5be1e3f089a83cad59531035d71ff4e4e613a4b5
|
7
|
+
data.tar.gz: d064cd8d3ac144f5fff2b5ab47284e6b8ec4ae7900802b2bbf9b39aaa6ae7cb1b64a1d5c534b3da67a23d644b31266b93a737f4571664c7a57e565ddedb4747e
|
data/lib/filterer/base.rb
CHANGED
@@ -6,15 +6,15 @@ module Filterer
|
|
6
6
|
attr_accessor :results, :meta, :direction, :sort, :params, :opts
|
7
7
|
|
8
8
|
class << self
|
9
|
-
attr_accessor :sort_options
|
9
|
+
attr_accessor :sort_options, :per_page_num, :per_page_allow_override
|
10
10
|
|
11
11
|
def sort_options
|
12
12
|
@sort_options ||= []
|
13
13
|
end
|
14
14
|
|
15
15
|
def inherited(subclass)
|
16
|
-
|
17
|
-
subclass.
|
16
|
+
%w(sort_options per_page_num per_page_allow_override).each do |x|
|
17
|
+
subclass.send("#{x}=", instance_variable_get("@#{x}"))
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -45,6 +45,11 @@ module Filterer
|
|
45
45
|
opts: opts
|
46
46
|
}
|
47
47
|
end
|
48
|
+
|
49
|
+
def per_page(num, opts = {})
|
50
|
+
@per_page_num = num
|
51
|
+
@per_page_allow_override = opts[:allow_override]
|
52
|
+
end
|
48
53
|
end
|
49
54
|
|
50
55
|
def initialize(params = {}, opts = {})
|
@@ -60,10 +65,18 @@ module Filterer
|
|
60
65
|
def setup_meta
|
61
66
|
@meta = {
|
62
67
|
page: [@params[:page].to_i, 1].max,
|
63
|
-
per_page:
|
68
|
+
per_page: get_per_page
|
64
69
|
}
|
65
70
|
end
|
66
71
|
|
72
|
+
def get_per_page
|
73
|
+
if self.class.per_page_allow_override && @params[:per_page].present?
|
74
|
+
@params[:per_page]
|
75
|
+
else
|
76
|
+
self.class.per_page_num || 20
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
67
80
|
def find_results
|
68
81
|
@results = starting_query
|
69
82
|
|
data/lib/filterer/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: filterer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Becker
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-03-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|