data_tables-responder 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +18 -0
- data/data_tables-responder.gemspec +2 -1
- data/lib/data_tables/modules/order.rb +10 -12
- data/lib/data_tables/modules/pagination.rb +10 -9
- data/lib/data_tables/modules/search.rb +13 -18
- data/lib/data_tables/responder/version.rb +1 -1
- data/lib/data_tables/responder.rb +9 -10
- data/lib/data_tables.rb +1 -1
- metadata +19 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a83b526e4f4224368d73806333dff683042e76cc
|
4
|
+
data.tar.gz: 135113fa38ca6d8df40315a0d5cde7372cf92739
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a403b7f8443f716245bb1a2c1714586d9f08c899ded9378bd742cc939a667ebd2a9cf0a0c738480ccb55157a0e6dacf5785419daa5964d52b50042341216f0f3
|
7
|
+
data.tar.gz: 64d5519e436855129d00dd227c79b9fabd39e60fec2676e311338bace7df56620925c2df7d0ad82bbdde4b9b462ff5867f296676e07880f8cab94619d63fb4df
|
data/.travis.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
language: ruby
|
2
|
+
sudo: false
|
3
|
+
rvm:
|
4
|
+
- 2.3.1
|
5
|
+
- 2.4.0
|
6
|
+
cache: bundler
|
7
|
+
script:
|
8
|
+
- bundle exec rspec
|
9
|
+
|
10
|
+
after_success:
|
11
|
+
- bundle exec codeclimate-test-reporter
|
12
|
+
|
13
|
+
addons:
|
14
|
+
postgresql: "9.3"
|
15
|
+
|
16
|
+
env:
|
17
|
+
- RSPEC_VERSION="<2.99"
|
18
|
+
- RSPEC_VERSION="~>3.0
|
@@ -34,7 +34,8 @@ Gem::Specification.new do |spec|
|
|
34
34
|
|
35
35
|
spec.add_development_dependency 'activerecord', rails_versions
|
36
36
|
spec.add_development_dependency 'pry-byebug'
|
37
|
-
spec.add_development_dependency '
|
37
|
+
spec.add_development_dependency 'database_cleaner'
|
38
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
38
39
|
spec.add_development_dependency 'rake', '~> 10.0'
|
39
40
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
40
41
|
end
|
@@ -4,20 +4,18 @@ module DataTables
|
|
4
4
|
|
5
5
|
attr_reader :scope, :context
|
6
6
|
|
7
|
-
def initialize(scope,
|
7
|
+
def initialize(model, scope, params)
|
8
8
|
@scope = scope.dup
|
9
|
-
@
|
9
|
+
@model = model
|
10
|
+
@params = params
|
10
11
|
end
|
11
12
|
|
12
13
|
def order
|
13
|
-
|
14
|
-
|
15
|
-
model = @scope.try(:model) || @scope
|
16
|
-
columns = orderable_columns(@request_parameters[:order], @request_parameters[:columns])
|
14
|
+
columns = orderable_columns(@params[:order], @params[:columns])
|
17
15
|
|
18
16
|
orders = DataTables::Responder.flat_keys_to_nested columns
|
19
17
|
|
20
|
-
order_by, join_hash = build_order(model, orders)
|
18
|
+
order_by, join_hash = build_order(@model, orders)
|
21
19
|
|
22
20
|
@scope = @scope.joins(join_hash)
|
23
21
|
|
@@ -49,13 +47,13 @@ module DataTables
|
|
49
47
|
protected
|
50
48
|
|
51
49
|
def orderable_columns(orders, columns)
|
52
|
-
|
53
|
-
|
54
|
-
if (
|
55
|
-
|
50
|
+
orders&.inject({}) do |collection, order|
|
51
|
+
column = columns[order[:column]]
|
52
|
+
if (column[:orderable] && column[:data].present?)
|
53
|
+
collection[column[:data]] = order[:dir]
|
56
54
|
end
|
55
|
+
collection
|
57
56
|
end
|
58
|
-
sums
|
59
57
|
end
|
60
58
|
|
61
59
|
end
|
@@ -3,21 +3,22 @@ module DataTables
|
|
3
3
|
module Modules
|
4
4
|
class Pagination
|
5
5
|
|
6
|
-
FIRST_PAGE =
|
6
|
+
FIRST_PAGE = '0'
|
7
|
+
DEFAULT_LENGTH = '10'
|
7
8
|
|
8
|
-
attr_reader :
|
9
|
+
attr_reader :scope, :context
|
9
10
|
|
10
|
-
def initialize(
|
11
|
-
@
|
12
|
-
@
|
13
|
-
@
|
11
|
+
def initialize(model, scope, params)
|
12
|
+
@scope = scope.dup
|
13
|
+
@model = model
|
14
|
+
@params = params
|
14
15
|
end
|
15
16
|
|
16
17
|
def paginate
|
17
|
-
start = (@
|
18
|
-
length = (@
|
18
|
+
start = (@params[:start] || FIRST_PAGE).to_i
|
19
|
+
length = (@params[:length] || DEFAULT_LENGTH).to_i
|
19
20
|
page = (start / length)
|
20
|
-
@
|
21
|
+
@scope.offset(page * length).limit(length)
|
21
22
|
end
|
22
23
|
|
23
24
|
end
|
@@ -4,20 +4,18 @@ module DataTables
|
|
4
4
|
|
5
5
|
attr_reader :scope, :context
|
6
6
|
|
7
|
-
def initialize(scope,
|
8
|
-
@scope = scope
|
9
|
-
@
|
7
|
+
def initialize(model, scope, params)
|
8
|
+
@scope = scope.dup
|
9
|
+
@model = model
|
10
|
+
@params = params
|
10
11
|
end
|
11
12
|
|
12
13
|
def search
|
13
|
-
|
14
|
-
|
15
|
-
model = @scope.try(:model) || @scope
|
16
|
-
columns = searchable_columns(default_search)
|
14
|
+
columns = searchable_columns(@params.dig(:search, :value), @params[:columns])
|
17
15
|
|
18
16
|
searches = DataTables::Responder.flat_keys_to_nested columns
|
19
17
|
|
20
|
-
search_by, join_hash = build_search(model, searches)
|
18
|
+
search_by, join_hash = build_search(@model, searches)
|
21
19
|
|
22
20
|
@scope = @scope.joins(join_hash)
|
23
21
|
|
@@ -55,7 +53,7 @@ module DataTables
|
|
55
53
|
# I'm pretty sure this is safe from SQL Injection
|
56
54
|
model.arel_table[column].matches("%#{query}%")
|
57
55
|
when :integer
|
58
|
-
model.arel_table[column].eq(value)
|
56
|
+
value = query&.to_i and model.arel_table[column].eq(value)
|
59
57
|
when :datetime
|
60
58
|
datetime = Time.parse(query)
|
61
59
|
range = (datetime-1.second)..(datetime+1.second)
|
@@ -67,18 +65,15 @@ module DataTables
|
|
67
65
|
result
|
68
66
|
end
|
69
67
|
|
70
|
-
def searchable_columns(default_search)
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
a[b[:data]] = value
|
68
|
+
def searchable_columns(default_search, columns)
|
69
|
+
columns&.inject({}) do |collection, column|
|
70
|
+
if (column[:searchable] && column[:data].present?)
|
71
|
+
if ((value = column.dig(:search, :value).present? ? column.dig(:search, :value) : default_search).present?)
|
72
|
+
collection[column[:data]] = value
|
76
73
|
end
|
77
74
|
end
|
78
|
-
|
75
|
+
collection
|
79
76
|
end
|
80
|
-
|
81
|
-
@searchable_columns
|
82
77
|
end
|
83
78
|
|
84
79
|
end
|
@@ -18,12 +18,11 @@ module DataTables
|
|
18
18
|
|
19
19
|
filtered_scope = original_scope&.dup || model.none
|
20
20
|
|
21
|
-
filtered_scope = order(filtered_scope, params)
|
21
|
+
filtered_scope = order(model, filtered_scope, params)
|
22
22
|
|
23
|
-
filtered_scope = search(filtered_scope, params)
|
23
|
+
filtered_scope = search(model, filtered_scope, params)
|
24
24
|
|
25
|
-
|
26
|
-
filtered_scope = paginate(original_scope, filtered_scope, params)
|
25
|
+
filtered_scope = paginate(model, filtered_scope, params)
|
27
26
|
end
|
28
27
|
|
29
28
|
def self.flat_keys_to_nested(hash)
|
@@ -34,16 +33,16 @@ module DataTables
|
|
34
33
|
end
|
35
34
|
end
|
36
35
|
|
37
|
-
def self.paginate(
|
38
|
-
Modules::Pagination.new(
|
36
|
+
def self.paginate(model, filtered_scope, params)
|
37
|
+
Modules::Pagination.new(model, filtered_scope, params).paginate
|
39
38
|
end
|
40
39
|
|
41
|
-
def self.search(filtered_scope, params)
|
42
|
-
Modules::Search.new(filtered_scope, params).search
|
40
|
+
def self.search(model, filtered_scope, params)
|
41
|
+
Modules::Search.new(model, filtered_scope, params).search
|
43
42
|
end
|
44
43
|
|
45
|
-
def self.order(filtered_scope, params)
|
46
|
-
Modules::Order.new(filtered_scope, params).order
|
44
|
+
def self.order(model, filtered_scope, params)
|
45
|
+
Modules::Order.new(model, filtered_scope, params).order
|
47
46
|
end
|
48
47
|
|
49
48
|
end
|
data/lib/data_tables.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: data_tables-responder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dale Stevens
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_model_serializers
|
@@ -98,20 +98,34 @@ dependencies:
|
|
98
98
|
- - ">="
|
99
99
|
- !ruby/object:Gem::Version
|
100
100
|
version: '0'
|
101
|
+
- !ruby/object:Gem::Dependency
|
102
|
+
name: database_cleaner
|
103
|
+
requirement: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
type: :development
|
109
|
+
prerelease: false
|
110
|
+
version_requirements: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
101
115
|
- !ruby/object:Gem::Dependency
|
102
116
|
name: bundler
|
103
117
|
requirement: !ruby/object:Gem::Requirement
|
104
118
|
requirements:
|
105
119
|
- - "~>"
|
106
120
|
- !ruby/object:Gem::Version
|
107
|
-
version: '1.
|
121
|
+
version: '1.3'
|
108
122
|
type: :development
|
109
123
|
prerelease: false
|
110
124
|
version_requirements: !ruby/object:Gem::Requirement
|
111
125
|
requirements:
|
112
126
|
- - "~>"
|
113
127
|
- !ruby/object:Gem::Version
|
114
|
-
version: '1.
|
128
|
+
version: '1.3'
|
115
129
|
- !ruby/object:Gem::Dependency
|
116
130
|
name: rake
|
117
131
|
requirement: !ruby/object:Gem::Requirement
|
@@ -149,6 +163,7 @@ extra_rdoc_files: []
|
|
149
163
|
files:
|
150
164
|
- ".gitignore"
|
151
165
|
- ".rspec"
|
166
|
+
- ".travis.yml"
|
152
167
|
- Gemfile
|
153
168
|
- LICENSE.txt
|
154
169
|
- README.md
|