seek 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -13,20 +13,20 @@ gem install seek
13
13
  # Examples
14
14
 
15
15
  ```ruby
16
- params = { page: '4', sort_order: 'desc', per_page: '1000' }
16
+ params = { page: '4', sort_direction: 'desc', per_page: '1000' }
17
17
 
18
18
  seek = Seek.new params,
19
19
  valid_sort_bys: %w{ first_name, last_name, age },
20
20
  max_per_page: 50,
21
21
  default_per_page: 10,
22
22
  default_sort_by: :age,
23
- default_sort_order: :asc
23
+ default_sort_direction: :asc
24
24
 
25
- seek.page #=> 4
26
- seek.per_page #=> 50
27
- seek.sort_by #=> 'age'
28
- seek.sort_order #=> 'desc
29
- seek.order #=> 'age desc'
25
+ seek.page #=> 4
26
+ seek.per_page #=> 50
27
+ seek.sort_by #=> 'age'
28
+ seek.sort_direction #=> 'desc
29
+ seek.order #=> 'age desc'
30
30
 
31
31
  seek.to_hash #=> Returns a Hash with all the parameters listed above.
32
32
  ```
data/lib/seek.rb CHANGED
@@ -16,12 +16,12 @@ class Seek
16
16
  self.page = params[:page]
17
17
  self.per_page = params[:per_page]
18
18
  self.sort_by = params[:sort_by]
19
- self.sort_order = params[:sort_order]
19
+ self.sort_direction = params[:sort_direction]
20
20
  self.max_per_page = options[:max_per_page]
21
21
  self.valid_sort_bys = options[:valid_sort_bys]
22
22
  self.default_per_page = options[:default_per_page]
23
23
  self.default_sort_by = options[:default_sort_by]
24
- self.default_sort_order = options[:default_sort_order]
24
+ self.default_sort_direction = options[:default_sort_direction]
25
25
  end
26
26
 
27
27
  def to_hash
@@ -29,7 +29,7 @@ class Seek
29
29
  page: page,
30
30
  per_page: per_page,
31
31
  sort_by: sort_by,
32
- sort_order: sort_order,
32
+ sort_direction: sort_direction,
33
33
  order: order,
34
34
  }
35
35
  end
data/lib/seek/sorting.rb CHANGED
@@ -1,9 +1,9 @@
1
1
  class Seek
2
2
  module Sorting
3
3
 
4
- attr_writer :sort_by, :sort_order, :valid_sort_bys, :default_sort_by, :default_sort_order
4
+ attr_writer :sort_by, :sort_direction, :valid_sort_bys, :default_sort_by, :default_sort_direction
5
5
 
6
- # Returns true if sort_by and sort_order are present.
6
+ # Returns true if sort_by and sort_direction are present.
7
7
  #
8
8
  def sortable?
9
9
  !!order
@@ -17,9 +17,9 @@ class Seek
17
17
  default_sort_by
18
18
  end
19
19
 
20
- def sort_order
21
- result = @sort_order.to_s.downcase
22
- valid_sort_orders.include?(result) ? result : valid_sort_orders.first
20
+ def sort_direction
21
+ result = @sort_direction.to_s.downcase
22
+ valid_sort_directions.include?(result) ? result : valid_sort_directions.first
23
23
  end
24
24
 
25
25
  # Useful for queries that require the format "first_name desc" (such as SQL or lucene)
@@ -28,7 +28,7 @@ class Seek
28
28
  #
29
29
  def order
30
30
  return if sort_by.to_s.empty?
31
- [sort_by, sort_order].join(' ')
31
+ [sort_by, sort_direction].join(' ')
32
32
  end
33
33
 
34
34
  def valid_sort_bys
@@ -42,14 +42,14 @@ class Seek
42
42
  valid_sort_bys.include?(result) ? result : valid_sort_bys.first
43
43
  end
44
44
 
45
- def default_sort_order
46
- result = @default_sort_order.to_s.downcase
47
- valid_sort_orders.include?(result) ? result : valid_sort_orders.first
45
+ def default_sort_direction
46
+ result = @default_sort_direction.to_s.downcase
47
+ valid_sort_directions.include?(result) ? result : valid_sort_directions.first
48
48
  end
49
49
 
50
50
  private
51
51
 
52
- def valid_sort_orders
52
+ def valid_sort_directions
53
53
  %w{ asc desc }
54
54
  end
55
55
 
data/lib/seek/version.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  class Seek
2
2
  module VERSION
3
3
  MAJOR = 0
4
- MINOR = 0
5
- TINY = 2
4
+ MINOR = 1
5
+ TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe Seek do
4
4
 
5
- let(:params) { { page: 4, per_page: 20, 'sort_by' => :first_name, sort_order: 'DESC' } }
5
+ let(:params) { { page: 4, per_page: 20, 'sort_by' => :first_name, sort_direction: 'DESC' } }
6
6
  let(:options) { { 'max_per_page' => 30, valid_sort_bys: %w{ age first_name last_name } } }
7
7
 
8
8
  let(:seek) { Seek.new params, options }
@@ -76,23 +76,23 @@ describe Seek do
76
76
  end
77
77
  end
78
78
 
79
- describe '#sort_order' do
79
+ describe '#sort_direction' do
80
80
  it 'comes from the params and is a String' do
81
- seek.sort_order.should == 'desc'
81
+ seek.sort_direction.should == 'desc'
82
82
  end
83
83
 
84
84
  it 'is ascending if nothing is specified' do
85
- Seek.new.sort_order.should == 'asc'
85
+ Seek.new.sort_direction.should == 'asc'
86
86
  end
87
87
 
88
88
  it 'is ascending if something invalid is specified' do
89
- Seek.new(sort_order: 'vertically').sort_order.should == 'asc'
89
+ Seek.new(sort_direction: 'vertically').sort_direction.should == 'asc'
90
90
  end
91
91
  end
92
92
  end
93
93
 
94
94
  describe '#order' do
95
- it 'is sort_by and sort_order separated by a space' do
95
+ it 'is sort_by and sort_direction separated by a space' do
96
96
  seek.order.should == 'first_name desc'
97
97
  end
98
98
 
@@ -102,7 +102,7 @@ describe Seek do
102
102
  end
103
103
 
104
104
  describe '#sortable?' do
105
- it 'is true if there is sort_by and sort_order' do
105
+ it 'is true if there is sort_by and sort_direction' do
106
106
  seek.should be_sortable
107
107
  end
108
108
 
@@ -113,7 +113,7 @@ describe Seek do
113
113
 
114
114
  describe '#to_hash' do
115
115
  it 'contains all params' do
116
- seek.to_hash.should == { page: 4, per_page: 20, sort_by: 'first_name', sort_order: 'desc', order: 'first_name desc' }
116
+ seek.to_hash.should == { page: 4, per_page: 20, sort_by: 'first_name', sort_direction: 'desc', order: 'first_name desc' }
117
117
  end
118
118
  end
119
119
 
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.2
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: