data_table 0.1.8 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +2 -2
- data/lib/data_table/active_record.rb +15 -0
- data/lib/data_table/version.rb +1 -1
- data/spec/active_record_data_table_spec.rb +10 -1
- metadata +9 -8
data/README.rdoc
CHANGED
@@ -25,8 +25,8 @@ in your controller:
|
|
25
25
|
respond_to do |wants|
|
26
26
|
wants.html
|
27
27
|
wants.json do
|
28
|
-
render(:json => Provider.for_data_table(self, %w(name fein
|
29
|
-
["<%= link_to(provider, provider) %>", provider.fein, provider.category, provider.county, provider.state]
|
28
|
+
render(:json => Provider.for_data_table(self, %w(name fein categories.name county state), %w(name fein)) do |provider|
|
29
|
+
["<%= link_to(provider, provider) %>", provider.fein, provider.category.name, provider.county, provider.state]
|
30
30
|
end)
|
31
31
|
end
|
32
32
|
end
|
@@ -1,12 +1,27 @@
|
|
1
1
|
module DataTable
|
2
2
|
module ActiveRecord
|
3
3
|
module ClassMethods
|
4
|
+
|
4
5
|
def _find_objects params, fields, search_fields
|
5
6
|
self.where(_where_conditions params[:sSearch], search_fields).
|
7
|
+
includes(_discover_joins fields).
|
6
8
|
order(_order_fields params, fields).
|
7
9
|
paginate :page => _page(params), :per_page => _per_page(params)
|
8
10
|
end
|
9
11
|
|
12
|
+
def _discover_joins fields
|
13
|
+
joins = Set.new
|
14
|
+
|
15
|
+
fields.each { |it|
|
16
|
+
field = it.split('.')
|
17
|
+
if (field.size == 2) then
|
18
|
+
joins.add field[0].singularize.to_sym
|
19
|
+
end
|
20
|
+
}
|
21
|
+
|
22
|
+
joins.collect
|
23
|
+
end
|
24
|
+
|
10
25
|
def _where_conditions query, search_fields
|
11
26
|
return if query.blank?
|
12
27
|
|
data/lib/data_table/version.rb
CHANGED
@@ -9,10 +9,11 @@ describe DataTable do
|
|
9
9
|
it "should find the objects required based on the params" do
|
10
10
|
params = {:sSearch => "answer", :iSortCol_0 => "0", :sSortDir_0 => "desc", :iDisplayLength => 10, :sEcho => 1}
|
11
11
|
|
12
|
+
mock(self)._discover_joins(%w(foo bar baz)) { [] }
|
12
13
|
mock(self)._where_conditions("answer", %w(foo bar)) { "where clause" }
|
13
14
|
mock(self)._order_fields(params, %w(foo bar baz)) { "order" }
|
14
15
|
|
15
|
-
mock(self).where("where clause") { mock!.order("order") { mock!.paginate({:page => :page, :per_page => :per_page}) { :answer } } }
|
16
|
+
mock(self).where("where clause") { mock!.includes([]) { mock!.order("order") { mock!.paginate({:page => :page, :per_page => :per_page}) { :answer } } } }
|
16
17
|
mock(self)._page(params) { :page }
|
17
18
|
mock(self)._per_page(params) { :per_page }
|
18
19
|
|
@@ -33,6 +34,14 @@ describe DataTable do
|
|
33
34
|
|
34
35
|
end
|
35
36
|
|
37
|
+
context "#_discover_joins" do
|
38
|
+
|
39
|
+
it "should return the joins on the fields" do
|
40
|
+
_discover_joins(%w(foo.bar foz.ber baz)).should == [:foo, :foz]
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
36
45
|
context "#_order_fields" do
|
37
46
|
|
38
47
|
it "should find the field name and pass the sort direction" do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: data_table
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 9
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 9
|
10
|
+
version: 0.1.9
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jason Dew
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2011-04-25 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -42,11 +42,12 @@ dependencies:
|
|
42
42
|
requirements:
|
43
43
|
- - ~>
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
hash:
|
45
|
+
hash: 1923831917
|
46
46
|
segments:
|
47
47
|
- 3
|
48
48
|
- 0
|
49
|
-
-
|
49
|
+
- pre
|
50
|
+
- 2
|
50
51
|
version: 3.0.pre2
|
51
52
|
type: :runtime
|
52
53
|
version_requirements: *id002
|
@@ -157,7 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
157
158
|
requirements: []
|
158
159
|
|
159
160
|
rubyforge_project: data_table
|
160
|
-
rubygems_version: 1.
|
161
|
+
rubygems_version: 1.4.2
|
161
162
|
signing_key:
|
162
163
|
specification_version: 3
|
163
164
|
summary: Simple data preparation from AR/Mongoid to the jQuery DataTables plugin
|