rest_framework 0.3.0 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/rest_framework/controller_mixins/base.rb +2 -2
- data/lib/rest_framework/controller_mixins/models.rb +8 -0
- data/lib/rest_framework/filters.rb +18 -4
- data/lib/rest_framework/paginators.rb +1 -0
- metadata +3 -4
- data/app/views/rest_framework/default.html.erb +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb9085823972b6991c739761eb1ec47ce012e9b0c40e0215199b1cc1f2e681c0
|
4
|
+
data.tar.gz: 7c211b54982077d586d35cd0c04401f1e7ec54cd5363234f5832651f605aee5d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a92b41406fa3d2723fe29e53ff38c129453b3357e6d21f51fb79de797812a2d20ea0dd5936ace48834084d00887658daf7be63bbb65e98d7cb7eee21fbe2fd89
|
7
|
+
data.tar.gz: 652d9e6c68f1688202d7ee52617bb73491f358afffcd99960bda6edc3acf2a6dd2942e278bcfeb7e86876754f16d9b8911af716b61eb179f021188ecd61e9dc8
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.2
|
@@ -182,9 +182,9 @@ module RESTFramework::BaseControllerMixin
|
|
182
182
|
hkwargs = kwargs.merge(html_kwargs)
|
183
183
|
begin
|
184
184
|
render(**hkwargs)
|
185
|
-
rescue ActionView::MissingTemplate # fallback to rest_framework layout
|
185
|
+
rescue ActionView::MissingTemplate # fallback to rest_framework layout
|
186
186
|
hkwargs[:layout] = "rest_framework"
|
187
|
-
hkwargs[:
|
187
|
+
hkwargs[:html] = ''
|
188
188
|
render(**hkwargs)
|
189
189
|
end
|
190
190
|
}
|
@@ -37,6 +37,9 @@ module RESTFramework::BaseModelControllerMixin
|
|
37
37
|
filterset_fields: nil,
|
38
38
|
ordering_fields: nil,
|
39
39
|
ordering_query_param: 'ordering',
|
40
|
+
search_fields: nil,
|
41
|
+
search_query_param: 'search',
|
42
|
+
search_case_sensitive: false,
|
40
43
|
|
41
44
|
# Other misc attributes.
|
42
45
|
create_from_recordset: true, # Option for `recordset.create` vs `Model.create` behavior.
|
@@ -89,6 +92,11 @@ module RESTFramework::BaseModelControllerMixin
|
|
89
92
|
return self.class.ordering_fields&.map(&:to_s) || self.get_fields
|
90
93
|
end
|
91
94
|
|
95
|
+
# Get a list of search fields for the current action.
|
96
|
+
def get_search_fields
|
97
|
+
return self.class.search_fields&.map(&:to_s) || self.get_fields
|
98
|
+
end
|
99
|
+
|
92
100
|
# Get a list of parameters allowed for the current action.
|
93
101
|
def get_allowed_parameters
|
94
102
|
return _get_specific_action_config(:allowed_action_parameters, :allowed_parameters)&.map(&:to_s)
|
@@ -15,7 +15,7 @@ class RESTFramework::ModelFilter < RESTFramework::BaseFilter
|
|
15
15
|
# Filter params for keys allowed by the current action's filterset_fields/fields config.
|
16
16
|
def _get_filter_params
|
17
17
|
fields = @controller.send(:get_filterset_fields)
|
18
|
-
return @controller.request.query_parameters.select { |p|
|
18
|
+
return @controller.request.query_parameters.select { |p, _|
|
19
19
|
fields.include?(p)
|
20
20
|
}.to_h.symbolize_keys # convert from HashWithIndifferentAccess to Hash w/keys
|
21
21
|
end
|
@@ -71,6 +71,20 @@ class RESTFramework::ModelOrderingFilter < RESTFramework::BaseFilter
|
|
71
71
|
end
|
72
72
|
|
73
73
|
|
74
|
-
#
|
75
|
-
|
76
|
-
#
|
74
|
+
# Multi-field text searching on models.
|
75
|
+
class RESTFramework::ModelSearchFilter < RESTFramework::BaseFilter
|
76
|
+
# Filter data according to the request query parameters.
|
77
|
+
def get_filtered_data(data)
|
78
|
+
fields = @controller.send(:get_search_fields)
|
79
|
+
search = @controller.request.query_parameters[@controller.send(:search_query_param)]
|
80
|
+
|
81
|
+
# Ensure we use array conditions to prevent SQL injection.
|
82
|
+
unless search.blank?
|
83
|
+
return data.where(fields.map { |f|
|
84
|
+
"CAST(#{f} AS text) #{@controller.send(:search_case_sensitive) ? "LIKE" : "ILIKE"} ?"
|
85
|
+
}.join(' OR '), *(["%#{search}%"] * fields.length))
|
86
|
+
end
|
87
|
+
|
88
|
+
return data
|
89
|
+
end
|
90
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rest_framework
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gregory N. Schmit
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-05-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -37,7 +37,6 @@ files:
|
|
37
37
|
- app/views/layouts/rest_framework.html.erb
|
38
38
|
- app/views/rest_framework/_head.html.erb
|
39
39
|
- app/views/rest_framework/_routes.html.erb
|
40
|
-
- app/views/rest_framework/default.html.erb
|
41
40
|
- lib/rest_framework.rb
|
42
41
|
- lib/rest_framework/controller_mixins.rb
|
43
42
|
- lib/rest_framework/controller_mixins/base.rb
|
@@ -73,7 +72,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
73
72
|
- !ruby/object:Gem::Version
|
74
73
|
version: '0'
|
75
74
|
requirements: []
|
76
|
-
rubygems_version: 3.
|
75
|
+
rubygems_version: 3.1.4
|
77
76
|
signing_key:
|
78
77
|
specification_version: 4
|
79
78
|
summary: A framework for DRY RESTful APIs in Ruby on Rails.
|
File without changes
|