rest_framework 0.3.0 → 0.3.6
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 +9 -0
- data/lib/rest_framework/errors.rb +0 -12
- data/lib/rest_framework/filters.rb +23 -6
- data/lib/rest_framework/paginators.rb +1 -0
- data/lib/rest_framework/serializers.rb +5 -11
- 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: 86f1b6f94bf7074dd30cf16be9f07fdc83df2bd477e09584f12882456e1405cf
|
4
|
+
data.tar.gz: b0d8bacaac76492876f13e8f402bb090a3e490f3bbf6656c88efb3cf52d2d1c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '02179633392aa9f9e7c873e38bcacfb1cd7c93b5caeef57c2ec112707b16fc069cae17686d899d4d6bf5cb0582dff469bac38e71081f7b5f20b5915298e6eb44'
|
7
|
+
data.tar.gz: 432da0162809905fc29e93194d616561ee0b9d93c23b194e77792fb9a7814062ae10025986c466510d3d5adfe2e4300de4104213444a30835626ed17c076f7b4
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.6
|
@@ -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,10 @@ module RESTFramework::BaseModelControllerMixin
|
|
37
37
|
filterset_fields: nil,
|
38
38
|
ordering_fields: nil,
|
39
39
|
ordering_query_param: 'ordering',
|
40
|
+
ordering_no_reorder: false,
|
41
|
+
search_fields: nil,
|
42
|
+
search_query_param: 'search',
|
43
|
+
search_ilike: false,
|
40
44
|
|
41
45
|
# Other misc attributes.
|
42
46
|
create_from_recordset: true, # Option for `recordset.create` vs `Model.create` behavior.
|
@@ -89,6 +93,11 @@ module RESTFramework::BaseModelControllerMixin
|
|
89
93
|
return self.class.ordering_fields&.map(&:to_s) || self.get_fields
|
90
94
|
end
|
91
95
|
|
96
|
+
# Get a list of search fields for the current action.
|
97
|
+
def get_search_fields
|
98
|
+
return self.class.search_fields&.map(&:to_s) || self.get_fields
|
99
|
+
end
|
100
|
+
|
92
101
|
# Get a list of parameters allowed for the current action.
|
93
102
|
def get_allowed_parameters
|
94
103
|
return _get_specific_action_config(:allowed_action_parameters, :allowed_parameters)&.map(&:to_s)
|
@@ -14,15 +14,3 @@ class RESTFramework::NilPassedToAPIResponseError < RESTFramework::Error
|
|
14
14
|
MSG
|
15
15
|
end
|
16
16
|
end
|
17
|
-
|
18
|
-
|
19
|
-
class RESTFramework::UnserializableError < RESTFramework::Error
|
20
|
-
def initialize(object)
|
21
|
-
@object = object
|
22
|
-
return super
|
23
|
-
end
|
24
|
-
|
25
|
-
def message
|
26
|
-
return "Unable to serialize `#{@object.inspect}` (of type `#{@object.class}`)."
|
27
|
-
end
|
28
|
-
end
|
@@ -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
|
@@ -38,8 +38,8 @@ class RESTFramework::ModelOrderingFilter < RESTFramework::BaseFilter
|
|
38
38
|
def _get_ordering
|
39
39
|
return nil if @controller.class.ordering_query_param.blank?
|
40
40
|
ordering_fields = @controller.send(:get_ordering_fields)
|
41
|
-
|
42
41
|
order_string = @controller.params[@controller.class.ordering_query_param]
|
42
|
+
|
43
43
|
unless order_string.blank?
|
44
44
|
ordering = {}
|
45
45
|
order_string.split(',').each do |field|
|
@@ -63,14 +63,31 @@ class RESTFramework::ModelOrderingFilter < RESTFramework::BaseFilter
|
|
63
63
|
# Order data according to the request query parameters.
|
64
64
|
def get_filtered_data(data)
|
65
65
|
ordering = self._get_ordering
|
66
|
+
reorder = !@controller.send(:ordering_no_reorder)
|
67
|
+
|
66
68
|
if ordering && !ordering.empty?
|
67
|
-
return data.order
|
69
|
+
return data.send(reorder ? :reorder : :order, _get_ordering)
|
68
70
|
end
|
71
|
+
|
69
72
|
return data
|
70
73
|
end
|
71
74
|
end
|
72
75
|
|
73
76
|
|
74
|
-
#
|
75
|
-
|
76
|
-
#
|
77
|
+
# Multi-field text searching on models.
|
78
|
+
class RESTFramework::ModelSearchFilter < RESTFramework::BaseFilter
|
79
|
+
# Filter data according to the request query parameters.
|
80
|
+
def get_filtered_data(data)
|
81
|
+
fields = @controller.send(:get_search_fields)
|
82
|
+
search = @controller.request.query_parameters[@controller.send(:search_query_param)]
|
83
|
+
|
84
|
+
# Ensure we use array conditions to prevent SQL injection.
|
85
|
+
unless search.blank?
|
86
|
+
return data.where(fields.map { |f|
|
87
|
+
"CAST(#{f} AS CHAR) #{@controller.send(:search_ilike) ? "ILIKE" : "LIKE"} ?"
|
88
|
+
}.join(' OR '), *(["%#{search}%"] * fields.length))
|
89
|
+
end
|
90
|
+
|
91
|
+
return data
|
92
|
+
end
|
93
|
+
end
|
@@ -105,18 +105,12 @@ class RESTFramework::NativeSerializer < RESTFramework::BaseSerializer
|
|
105
105
|
|
106
106
|
# Convert the object (record or recordset) to Ruby primitives.
|
107
107
|
def serialize
|
108
|
-
|
109
|
-
begin
|
110
|
-
if @object.is_a?(Enumerable)
|
111
|
-
return @object.map { |r| r.serializable_hash(self.get_serializer_config) }
|
112
|
-
end
|
113
|
-
return @object.serializable_hash(self.get_serializer_config)
|
114
|
-
rescue NoMethodError
|
115
|
-
end
|
116
|
-
end
|
108
|
+
raise "No object available to serialize!" unless @object
|
117
109
|
|
118
|
-
|
119
|
-
|
110
|
+
if @object.is_a?(Enumerable)
|
111
|
+
return @object.map { |r| r.serializable_hash(self.get_serializer_config) }
|
112
|
+
end
|
113
|
+
return @object.serializable_hash(self.get_serializer_config)
|
120
114
|
end
|
121
115
|
|
122
116
|
# Allow a serializer instance to be used as a hash directly in a nested serializer config.
|
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.6
|
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-12 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
|