data_table 0.2.7 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +41 -40
- data/README.rdoc +8 -0
- data/data_table.gemspec +0 -1
- data/lib/data_table/base.rb +2 -1
- data/lib/data_table/mongoid.rb +6 -2
- data/lib/data_table/version.rb +1 -1
- data/spec/data_table_spec.rb +21 -0
- data/spec/mongoid_data_table_spec.rb +2 -2
- metadata +7 -18
data/Gemfile.lock
CHANGED
@@ -1,72 +1,73 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
data_table (0.2.
|
4
|
+
data_table (0.2.7)
|
5
5
|
rails (~> 3.0.0)
|
6
|
-
will_paginate (~> 3.0.pre2)
|
7
6
|
|
8
7
|
GEM
|
9
8
|
remote: http://rubygems.org/
|
10
9
|
specs:
|
11
10
|
abstract (1.0.0)
|
12
|
-
actionmailer (3.0.
|
13
|
-
actionpack (= 3.0.
|
14
|
-
mail (~> 2.2.
|
15
|
-
actionpack (3.0.
|
16
|
-
activemodel (= 3.0.
|
17
|
-
activesupport (= 3.0.
|
11
|
+
actionmailer (3.0.10)
|
12
|
+
actionpack (= 3.0.10)
|
13
|
+
mail (~> 2.2.19)
|
14
|
+
actionpack (3.0.10)
|
15
|
+
activemodel (= 3.0.10)
|
16
|
+
activesupport (= 3.0.10)
|
18
17
|
builder (~> 2.1.2)
|
19
18
|
erubis (~> 2.6.6)
|
20
|
-
i18n (~> 0.
|
19
|
+
i18n (~> 0.5.0)
|
21
20
|
rack (~> 1.2.1)
|
22
|
-
rack-mount (~> 0.6.
|
21
|
+
rack-mount (~> 0.6.14)
|
23
22
|
rack-test (~> 0.5.7)
|
24
23
|
tzinfo (~> 0.3.23)
|
25
|
-
activemodel (3.0.
|
26
|
-
activesupport (= 3.0.
|
24
|
+
activemodel (3.0.10)
|
25
|
+
activesupport (= 3.0.10)
|
27
26
|
builder (~> 2.1.2)
|
28
|
-
i18n (~> 0.
|
29
|
-
activerecord (3.0.
|
30
|
-
activemodel (= 3.0.
|
31
|
-
activesupport (= 3.0.
|
32
|
-
arel (~> 2.0.
|
27
|
+
i18n (~> 0.5.0)
|
28
|
+
activerecord (3.0.10)
|
29
|
+
activemodel (= 3.0.10)
|
30
|
+
activesupport (= 3.0.10)
|
31
|
+
arel (~> 2.0.10)
|
33
32
|
tzinfo (~> 0.3.23)
|
34
|
-
activeresource (3.0.
|
35
|
-
activemodel (= 3.0.
|
36
|
-
activesupport (= 3.0.
|
37
|
-
activesupport (3.0.
|
38
|
-
arel (2.0.
|
33
|
+
activeresource (3.0.10)
|
34
|
+
activemodel (= 3.0.10)
|
35
|
+
activesupport (= 3.0.10)
|
36
|
+
activesupport (3.0.10)
|
37
|
+
arel (2.0.10)
|
39
38
|
builder (2.1.2)
|
40
39
|
diff-lcs (1.1.2)
|
41
40
|
erubis (2.6.6)
|
42
41
|
abstract (>= 1.0.0)
|
43
42
|
i18n (0.5.0)
|
44
|
-
mail (2.2.
|
43
|
+
mail (2.2.19)
|
45
44
|
activesupport (>= 2.3.6)
|
46
45
|
i18n (>= 0.4.0)
|
47
46
|
mime-types (~> 1.16)
|
48
47
|
treetop (~> 1.4.8)
|
49
48
|
mime-types (1.16)
|
50
|
-
polyglot (0.3.
|
51
|
-
rack (1.2.
|
52
|
-
rack-mount (0.6.
|
49
|
+
polyglot (0.3.2)
|
50
|
+
rack (1.2.3)
|
51
|
+
rack-mount (0.6.14)
|
53
52
|
rack (>= 1.0.0)
|
54
53
|
rack-test (0.5.7)
|
55
54
|
rack (>= 1.0)
|
56
|
-
rails (3.0.
|
57
|
-
actionmailer (= 3.0.
|
58
|
-
actionpack (= 3.0.
|
59
|
-
activerecord (= 3.0.
|
60
|
-
activeresource (= 3.0.
|
61
|
-
activesupport (= 3.0.
|
55
|
+
rails (3.0.10)
|
56
|
+
actionmailer (= 3.0.10)
|
57
|
+
actionpack (= 3.0.10)
|
58
|
+
activerecord (= 3.0.10)
|
59
|
+
activeresource (= 3.0.10)
|
60
|
+
activesupport (= 3.0.10)
|
62
61
|
bundler (~> 1.0)
|
63
|
-
railties (= 3.0.
|
64
|
-
railties (3.0.
|
65
|
-
actionpack (= 3.0.
|
66
|
-
activesupport (= 3.0.
|
62
|
+
railties (= 3.0.10)
|
63
|
+
railties (3.0.10)
|
64
|
+
actionpack (= 3.0.10)
|
65
|
+
activesupport (= 3.0.10)
|
67
66
|
rake (>= 0.8.7)
|
67
|
+
rdoc (~> 3.4)
|
68
68
|
thor (~> 0.14.4)
|
69
|
-
rake (0.
|
69
|
+
rake (0.9.2)
|
70
|
+
rdoc (3.9.4)
|
70
71
|
rr (1.0.0)
|
71
72
|
rspec (2.0.1)
|
72
73
|
rspec-core (~> 2.0.1)
|
@@ -80,10 +81,10 @@ GEM
|
|
80
81
|
rspec-expectations (~> 2.0.1)
|
81
82
|
shoulda (2.11.3)
|
82
83
|
thor (0.14.6)
|
83
|
-
treetop (1.4.
|
84
|
+
treetop (1.4.10)
|
85
|
+
polyglot
|
84
86
|
polyglot (>= 0.3.1)
|
85
|
-
tzinfo (0.3.
|
86
|
-
will_paginate (3.0.pre2)
|
87
|
+
tzinfo (0.3.29)
|
87
88
|
|
88
89
|
PLATFORMS
|
89
90
|
ruby
|
data/README.rdoc
CHANGED
data/data_table.gemspec
CHANGED
data/lib/data_table/base.rb
CHANGED
@@ -12,10 +12,11 @@ module DataTable
|
|
12
12
|
block = (explicit_block or implicit_block)
|
13
13
|
|
14
14
|
objects = _find_objects params, fields, search_fields
|
15
|
+
matching_count = objects.respond_to?(:total_entries) ? objects.total_entries : _matching_count(params, search_fields)
|
15
16
|
|
16
17
|
{:sEcho => params[:sEcho].to_i,
|
17
18
|
:iTotalRecords => self.count,
|
18
|
-
:iTotalDisplayRecords =>
|
19
|
+
:iTotalDisplayRecords => matching_count,
|
19
20
|
:aaData => _yield_and_render_array(controller, objects, block)
|
20
21
|
}.to_json.html_safe
|
21
22
|
end
|
data/lib/data_table/mongoid.rb
CHANGED
@@ -4,8 +4,12 @@ module DataTable
|
|
4
4
|
def _find_objects params, fields, search_fields
|
5
5
|
self.where(_where_conditions params[:sSearch], search_fields).
|
6
6
|
order_by(_order_by_fields params, fields).
|
7
|
-
|
8
|
-
|
7
|
+
page(_page params).
|
8
|
+
per(_per_page params)
|
9
|
+
end
|
10
|
+
|
11
|
+
def _matching_count params, search_fields
|
12
|
+
self.where(_where_conditions params[:sSearch], search_fields).count
|
9
13
|
end
|
10
14
|
|
11
15
|
def _where_conditions raw_query, search_fields
|
data/lib/data_table/version.rb
CHANGED
data/spec/data_table_spec.rb
CHANGED
@@ -32,6 +32,27 @@ describe DataTable do
|
|
32
32
|
result.should == {:sEcho => 1, :iTotalRecords => 42, :iTotalDisplayRecords => 10, :aaData => :results}.to_json.html_safe
|
33
33
|
end
|
34
34
|
|
35
|
+
# won't work because of ruby 1.9.2 bug... https://gist.github.com/455547
|
36
|
+
# it "should work with a pagination library that doesn't respond to #total_entries" do
|
37
|
+
# params = {:sSearch => "answer", :iSortCol_0 => "0", :sSortDir_0 => "desc", :iDisplayLength => "10", :sEcho => "1"}
|
38
|
+
# controller = mock!.params { params }.subject
|
39
|
+
#
|
40
|
+
# fields = %w(foo bar baz)
|
41
|
+
# search_fields = %w(foo bar)
|
42
|
+
#
|
43
|
+
# mock(self).count { 42 }
|
44
|
+
# mock(self)._matching_count(params, search_fields) { 10 }
|
45
|
+
# mock(self)._find_objects(params, fields, search_fields) { :objects }
|
46
|
+
# mock(self)._yield_and_render_array(controller, :objects, :block) { :results }
|
47
|
+
#
|
48
|
+
# result = for_data_table(controller, fields, search_fields, :block)
|
49
|
+
# result.should == {:sEcho => 1, :iTotalRecords => 42, :iTotalDisplayRecords => 10, :aaData => :results}.to_json.html_safe
|
50
|
+
# end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
context "#_yield_and_render_array" do
|
55
|
+
|
35
56
|
end
|
36
57
|
|
37
58
|
context "#_yield_and_render_array" do
|
@@ -12,8 +12,8 @@ describe DataTable do
|
|
12
12
|
mock(self)._order_by_fields(params, %w(foo bar baz)) { "order by" }
|
13
13
|
|
14
14
|
mock(self)._page(params) { :page }
|
15
|
-
mock(self)._per_page(params) { :per_page }
|
16
|
-
mock(self).where("where clause") { mock!.order_by("order by") { mock!.
|
15
|
+
mock(self)._per_page(params) { :per_page }
|
16
|
+
mock(self).where("where clause") { mock!.order_by("order by") { mock!.page(:page) { mock!.per(:per_page) { :answer } } } }
|
17
17
|
|
18
18
|
_find_objects(params, %w(foo bar baz), %w(foo bar)).should == :answer
|
19
19
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: data_table
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.3.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Jason Dew
|
@@ -24,50 +24,39 @@ dependencies:
|
|
24
24
|
version: 3.0.0
|
25
25
|
type: :runtime
|
26
26
|
version_requirements: *id001
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: will_paginate
|
29
|
-
prerelease: false
|
30
|
-
requirement: &id002 !ruby/object:Gem::Requirement
|
31
|
-
none: false
|
32
|
-
requirements:
|
33
|
-
- - "="
|
34
|
-
- !ruby/object:Gem::Version
|
35
|
-
version: 3.0.pre2
|
36
|
-
type: :runtime
|
37
|
-
version_requirements: *id002
|
38
27
|
- !ruby/object:Gem::Dependency
|
39
28
|
name: rspec
|
40
29
|
prerelease: false
|
41
|
-
requirement: &
|
30
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
42
31
|
none: false
|
43
32
|
requirements:
|
44
33
|
- - ~>
|
45
34
|
- !ruby/object:Gem::Version
|
46
35
|
version: 2.0.0
|
47
36
|
type: :development
|
48
|
-
version_requirements: *
|
37
|
+
version_requirements: *id002
|
49
38
|
- !ruby/object:Gem::Dependency
|
50
39
|
name: shoulda
|
51
40
|
prerelease: false
|
52
|
-
requirement: &
|
41
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
42
|
none: false
|
54
43
|
requirements:
|
55
44
|
- - ~>
|
56
45
|
- !ruby/object:Gem::Version
|
57
46
|
version: 2.11.0
|
58
47
|
type: :development
|
59
|
-
version_requirements: *
|
48
|
+
version_requirements: *id003
|
60
49
|
- !ruby/object:Gem::Dependency
|
61
50
|
name: rr
|
62
51
|
prerelease: false
|
63
|
-
requirement: &
|
52
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
64
53
|
none: false
|
65
54
|
requirements:
|
66
55
|
- - ~>
|
67
56
|
- !ruby/object:Gem::Version
|
68
57
|
version: 1.0.0
|
69
58
|
type: :development
|
70
|
-
version_requirements: *
|
59
|
+
version_requirements: *id004
|
71
60
|
description: Simple data preparation from AR/Mongoid to the jQuery DataTables plugin
|
72
61
|
email:
|
73
62
|
- jason.dew@gmail.com
|