seek 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -18,6 +18,7 @@ params = { page: '4', sort_order: 'desc', per_page: '1000' }
18
18
  seek = Seek.new params,
19
19
  valid_sort_bys: %w{ first_name, last_name, age },
20
20
  max_per_page: 50,
21
+ default_per_page: 10,
21
22
  default_sort_by: :age,
22
23
  default_sort_order: :asc
23
24
 
@@ -27,6 +28,5 @@ seek.sort_by #=> 'age'
27
28
  seek.sort_order #=> 'desc
28
29
  seek.order #=> 'age desc'
29
30
 
30
- seek.to_hash
31
- #=> Returns a Hash with all the parameters listed above.
31
+ seek.to_hash #=> Returns a Hash with all the parameters listed above.
32
32
  ```
@@ -19,6 +19,7 @@ class Seek
19
19
  self.sort_order = params[:sort_order]
20
20
  self.max_per_page = options[:max_per_page]
21
21
  self.valid_sort_bys = options[:valid_sort_bys]
22
+ self.default_per_page = options[:default_per_page]
22
23
  self.default_sort_by = options[:default_sort_by]
23
24
  self.default_sort_order = options[:default_sort_order]
24
25
  end
@@ -3,14 +3,19 @@ require 'positify'
3
3
  class Seek
4
4
  module Pagination
5
5
 
6
- attr_writer :page, :per_page, :max_per_page
6
+ attr_writer :page, :per_page, :max_per_page, :default_per_page
7
7
 
8
8
  def page
9
9
  Positify.it @page
10
10
  end
11
11
 
12
12
  def per_page
13
- Positify.it @per_page, max: max_per_page
13
+ if @per_page.to_i > 0
14
+ result = @per_page
15
+ else
16
+ result = default_per_page
17
+ end
18
+ Positify.it(result, max: max_per_page)
14
19
  end
15
20
 
16
21
  def max_per_page
@@ -21,5 +26,13 @@ class Seek
21
26
  end
22
27
  end
23
28
 
29
+ def default_per_page
30
+ if @default_per_page.to_i > 0
31
+ @default_per_page.to_i
32
+ else
33
+ self.class.config.default_per_page
34
+ end
35
+ end
36
+
24
37
  end
25
38
  end
@@ -2,7 +2,7 @@ class Seek
2
2
  module VERSION
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- TINY = 1
5
+ TINY = 2
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -20,6 +20,10 @@ describe Seek do
20
20
  end
21
21
 
22
22
  describe '#per_page' do
23
+ it 'takes the default from the configuration if nothing provided' do
24
+ Seek.new.per_page.should == 20
25
+ end
26
+
23
27
  it 'comes from the params' do
24
28
  seek.per_page.should == 20
25
29
  end
@@ -29,9 +33,9 @@ describe Seek do
29
33
  seek.per_page.should == 15
30
34
  end
31
35
 
32
- it 'does not become negative on weird values' do
36
+ it 'falls back to the default on weird values' do
33
37
  seek = Seek.new params.merge(per_page: 'what?')
34
- seek.per_page.should == 1
38
+ seek.per_page.should == 20
35
39
  end
36
40
  end
37
41
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: seek
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: