sort_this 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +12 -3
- data/Gemfile +3 -3
- data/Gemfile.rails3.2 +11 -0
- data/README.md +6 -5
- data/lib/sort_this/active_record.rb +12 -2
- data/lib/sort_this/version.rb +1 -1
- data/lib/sort_this.rb +2 -0
- data/spec/active_record_spec.rb +0 -4
- data/spec/spec_helper.rb +1 -1
- metadata +4 -3
data/.travis.yml
CHANGED
@@ -1,8 +1,17 @@
|
|
1
1
|
language: ruby
|
2
|
+
|
2
3
|
rvm:
|
3
|
-
-
|
4
|
-
-
|
4
|
+
- 1.9.2
|
5
|
+
- 1.9.3
|
6
|
+
- 2.0.0
|
7
|
+
|
5
8
|
gemfile:
|
6
9
|
- Gemfile
|
10
|
+
- Gemfile.rails3.2
|
7
11
|
- Gemfile.rails3.1
|
8
|
-
- Gemfile.rails3.0
|
12
|
+
- Gemfile.rails3.0
|
13
|
+
|
14
|
+
matrix:
|
15
|
+
exclude:
|
16
|
+
- rvm: 1.9.2
|
17
|
+
gemfile: Gemfile
|
data/Gemfile
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
gem 'rails', '~>
|
3
|
+
gem 'rails', '~> 4.0.0.beta', github: 'rails/rails', branch: 'master'
|
4
4
|
gem 'memoist', '0.2.0'
|
5
5
|
|
6
6
|
gem 'rspec', '2.12.0'
|
7
|
-
gem 'sqlite3'
|
7
|
+
gem 'sqlite3'
|
8
8
|
gem 'factory_girl', '4.1.0'
|
9
|
-
gem 'database_cleaner', '0.
|
9
|
+
gem 'database_cleaner', '1.0.0.RC1'
|
10
10
|
gem 'capybara', '2.0.1'
|
11
11
|
gem 'rake'
|
data/Gemfile.rails3.2
ADDED
data/README.md
CHANGED
@@ -36,7 +36,7 @@ The options are
|
|
36
36
|
|
37
37
|
column_name: (Optional) The name of the column to sort on. If left blank it will use the sort name.
|
38
38
|
default: (Optional) Defines a default sort if provided. The valid options are 'ASC' or 'DESC'.
|
39
|
-
table_name
|
39
|
+
table_name: (Optional) Overrides the table name used, should usually be used in coordination with joins.
|
40
40
|
joins: (Optional) Defines an association to join on, this should be provided if the column is in another table. ** Requires table name to be set. **
|
41
41
|
This is what you would usually pass into a joins or includes clause for ActiveRecord.
|
42
42
|
clause: (Optional) Overrides the clause used for the sort.
|
@@ -71,7 +71,10 @@ In you controller define a default sort
|
|
71
71
|
|
72
72
|
Defined Highest to Lowest priority
|
73
73
|
|
74
|
-
-
|
74
|
+
- Options on the `sortable` controller options
|
75
|
+
- Limiting which actions it can be applied on
|
76
|
+
- Allowing different types of sorts for different actions (defining multiple sortables)
|
77
|
+
- Customized sort parameters
|
75
78
|
- Being able to define multiple column sorts
|
76
79
|
|
77
80
|
Something like:
|
@@ -84,11 +87,9 @@ Defined Highest to Lowest priority
|
|
84
87
|
|
85
88
|
not sure how that'd be called though...
|
86
89
|
|
90
|
+
- Throw error when the table_name option is not set and joins is set.
|
87
91
|
- Define a default scope and remove from the sort method, gives more control to developer.
|
88
92
|
- Define scopes for each sort defined (individual sort scopes)
|
89
|
-
- Add the ability to customize the sort and direction parameters
|
90
|
-
- Testing on different databases (should probably hit postgresql and mysql unless the way SQLite handles it in the same way)
|
91
|
-
- Define rails 3.0 with ruby 1.8.7 gemfile for travis ci tests as 1.8.7 is still prevelant for 3.0
|
92
93
|
|
93
94
|
## Contributing
|
94
95
|
|
@@ -75,14 +75,14 @@ module SortThis
|
|
75
75
|
order_clauses << sort_clause
|
76
76
|
end
|
77
77
|
|
78
|
-
query =
|
78
|
+
query = base_query
|
79
79
|
query = joins(table_joins.uniq!) unless table_joins.empty?
|
80
80
|
query = query.order(order_clauses.join(', '))
|
81
81
|
query
|
82
82
|
end
|
83
83
|
|
84
84
|
def sort(sort_column = nil, sort_direction = DEFAULT_SORT_DIRECTION)
|
85
|
-
query =
|
85
|
+
query = base_query
|
86
86
|
|
87
87
|
# sanitize the sort column and direction
|
88
88
|
sort_column = sort_column.to_s.downcase.to_sym
|
@@ -114,6 +114,16 @@ module SortThis
|
|
114
114
|
|
115
115
|
query
|
116
116
|
end
|
117
|
+
|
118
|
+
private
|
119
|
+
|
120
|
+
def base_query
|
121
|
+
if Rails.version < '4.0'
|
122
|
+
scoped
|
123
|
+
else
|
124
|
+
all
|
125
|
+
end
|
126
|
+
end
|
117
127
|
|
118
128
|
end
|
119
129
|
end
|
data/lib/sort_this/version.rb
CHANGED
data/lib/sort_this.rb
CHANGED
data/spec/active_record_spec.rb
CHANGED
@@ -280,10 +280,6 @@ describe SortThis::ActiveRecord do
|
|
280
280
|
:vendor_name => {:column_name => :name, :table_name => 'vendors', :joins => :vendor}
|
281
281
|
end
|
282
282
|
|
283
|
-
it 'should return a relation' do
|
284
|
-
Quote.sort.class.should == ActiveRecord::Relation
|
285
|
-
end
|
286
|
-
|
287
283
|
context 'default parameters' do
|
288
284
|
it 'should sort by quote price ascending' do
|
289
285
|
Quote.sort.should == [quote3, quote2, quote1, quote4]
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sort_this
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-03-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -60,6 +60,7 @@ files:
|
|
60
60
|
- Gemfile.rails3.0.lock
|
61
61
|
- Gemfile.rails3.1
|
62
62
|
- Gemfile.rails3.1.lock
|
63
|
+
- Gemfile.rails3.2
|
63
64
|
- LICENSE.txt
|
64
65
|
- README.md
|
65
66
|
- Rakefile
|
@@ -92,7 +93,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
92
93
|
version: '0'
|
93
94
|
segments:
|
94
95
|
- 0
|
95
|
-
hash:
|
96
|
+
hash: 1981168485553352344
|
96
97
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
98
|
none: false
|
98
99
|
requirements:
|