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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 852f75a7abb5961f620080843aa3c4e27f801cda
4
- data.tar.gz: fb3a53d1e407ed3f78c35d8180ea07625f9c8aef
3
+ metadata.gz: ed26d0a881cdb7a6d59cd1f624cd509c4e8a37ef
4
+ data.tar.gz: 8447cb8b4ae3e5b6ebb1466bef6e608c1058be63
5
5
  SHA512:
6
- metadata.gz: a913462e9c327201503d837f81d9c559f1808eaff8fc0a32fe3d5daa0cd18ecd258d6f921d9b422d5b05202a2d70c14703b05e5e1af5ecad89e8c3a43403cf41
7
- data.tar.gz: 4e6fab8accf2ccbd61803c0108c722f20e3b0bd48b14428e255aa5b08e62db3cf7cbc99efafbe7199f96459c4483b0bd9479c388b767df859bcecac4360c6512
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
- if @sort_options.present?
17
- subclass.sort_options = @sort_options
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: 10
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
 
@@ -1,3 +1,3 @@
1
1
  module Filterer
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.1"
3
3
  end
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.1.1
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: 2013-12-22 00:00:00.000000000 Z
11
+ date: 2014-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails