rest_framework 0.0.10 → 0.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c3691667e86ee77e9d15a1732d0013687a2e63a062a4ff01d1c6d8cc66f45fc
|
4
|
+
data.tar.gz: 6bcab926c283feb9a0643a06eab750f941882e5b56b294c59794f64a966883bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 204e0b5ea7b46710968a6274791f9e0f676db34f4eaefa1cf831fe8f9e4ab1f076a24b0375ef0554e1c4b57db3d1787adeebc31c4201da40b504aded51ca097b
|
7
|
+
data.tar.gz: 7e46ed5bbe61832045207664d679ecf394aead2928cdd78a1b29873087b78130546fd80595fe443680d5c26eebfa8bf5f23246b56a9a4a83e801c7763c024c76
|
@@ -46,7 +46,7 @@
|
|
46
46
|
<div class="tab-content w-100 pt-3">
|
47
47
|
<div class="tab-pane fade show active" id="tab-json" role="tab">
|
48
48
|
<% if @json_payload %>
|
49
|
-
<div><pre><code class="language-json"><%= JSON.pretty_generate(JSON.parse(@json_payload)) %></code></pre></div>
|
49
|
+
<div><pre><code class="language-json"><%= JSON.pretty_generate(JSON.parse(@json_payload)) unless @json_payload == '' %></code></pre></div>
|
50
50
|
<% end %>
|
51
51
|
</div>
|
52
52
|
<div class="tab-pane fade" id="tab-xml" role="tab">
|
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.12
|
@@ -74,35 +74,42 @@ module RESTFramework
|
|
74
74
|
}.select { |r| r[:path].start_with?(request.path) }
|
75
75
|
end
|
76
76
|
|
77
|
-
# Helper alias for `respond_to`/`render
|
78
|
-
#
|
79
|
-
def api_response(payload, html_kwargs: nil, json_kwargs: nil, xml_kwargs: nil, **kwargs)
|
77
|
+
# Helper alias for `respond_to`/`render`. `payload` should be already serialized to Ruby
|
78
|
+
# primitives.
|
79
|
+
def api_response(payload=nil, html_kwargs: nil, json_kwargs: nil, xml_kwargs: nil, **kwargs)
|
80
80
|
html_kwargs ||= {}
|
81
81
|
json_kwargs ||= {}
|
82
82
|
xml_kwargs ||= {}
|
83
83
|
|
84
|
-
#
|
85
|
-
|
86
|
-
kwargs[:status] = 204
|
87
|
-
end
|
84
|
+
# allow blank (no-content) responses
|
85
|
+
@blank = kwargs[:blank]
|
88
86
|
|
89
87
|
respond_to do |format|
|
90
|
-
if
|
91
|
-
format.json {
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
88
|
+
if @blank
|
89
|
+
format.json {head :no_content}
|
90
|
+
format.xml {head :no_content}
|
91
|
+
else
|
92
|
+
if payload.respond_to?(:to_json)
|
93
|
+
format.json {
|
94
|
+
kwargs = kwargs.merge(json_kwargs)
|
95
|
+
render(json: payload, layout: false, **kwargs)
|
96
|
+
}
|
97
|
+
end
|
98
|
+
if payload.respond_to?(:to_xml)
|
99
|
+
format.xml {
|
100
|
+
kwargs = kwargs.merge(xml_kwargs)
|
101
|
+
render(xml: payload, layout: false, **kwargs)
|
102
|
+
}
|
103
|
+
end
|
101
104
|
end
|
102
105
|
format.html {
|
103
106
|
@payload = payload
|
104
|
-
@json_payload =
|
105
|
-
@xml_payload =
|
107
|
+
@json_payload = ''
|
108
|
+
@xml_payload = ''
|
109
|
+
unless @blank
|
110
|
+
@json_payload = payload.to_json if payload.respond_to?(:to_json)
|
111
|
+
@xml_payload = payload.to_xml if payload.respond_to?(:to_xml)
|
112
|
+
end
|
106
113
|
@template_logo_text ||= "Rails REST Framework"
|
107
114
|
@title ||= self.controller_name.camelize
|
108
115
|
@routes ||= self._get_routes
|
@@ -67,7 +67,7 @@ module RESTFramework
|
|
67
67
|
# Filter the request body for keys in current action's allowed_parameters/fields config.
|
68
68
|
def _get_parameter_values_from_request_body
|
69
69
|
fields = self.get_allowed_parameters || self.get_fields
|
70
|
-
return @
|
70
|
+
return @_get_parameter_values_from_request_body ||= (request.request_parameters.select { |p|
|
71
71
|
fields.include?(p.to_sym) || fields.include?(p.to_s)
|
72
72
|
})
|
73
73
|
end
|
@@ -77,7 +77,7 @@ module RESTFramework
|
|
77
77
|
# Filter params for keys allowed by the current action's filterset_fields/fields config.
|
78
78
|
def _get_filterset_values_from_params
|
79
79
|
fields = self.filterset_fields || self.get_fields
|
80
|
-
return @
|
80
|
+
return @_get_filterset_values_from_params ||= request.query_parameters.select { |p|
|
81
81
|
fields.include?(p.to_sym) || fields.include?(p.to_s)
|
82
82
|
}
|
83
83
|
end
|
@@ -59,7 +59,7 @@ module RESTFramework
|
|
59
59
|
return serializer_config if serializer_config
|
60
60
|
|
61
61
|
# otherwise, build a serializer config from fields
|
62
|
-
fields = @controller.send(:get_fields)
|
62
|
+
fields = @controller.send(:get_fields) if @controller
|
63
63
|
unless fields.blank?
|
64
64
|
columns, methods = fields.partition { |f| f.to_s.in?(@model.column_names) }
|
65
65
|
return {only: columns, methods: methods}
|
@@ -68,54 +68,41 @@ module RESTFramework
|
|
68
68
|
return {}
|
69
69
|
end
|
70
70
|
|
71
|
-
#
|
72
|
-
def
|
73
|
-
|
74
|
-
|
75
|
-
return
|
76
|
-
end
|
77
|
-
|
78
|
-
# Second base case: found a serializer instance, so evaluate it and return it.
|
79
|
-
if node.is_a?(BaseSerializer)
|
80
|
-
return node.get_resolved_serializer_config
|
71
|
+
# Convert the object(s) to Ruby primitives.
|
72
|
+
def serialize
|
73
|
+
if @object
|
74
|
+
@many = @object.respond_to?(:each) if @many.nil?
|
75
|
+
return @object.as_json(self.get_serializer_config)
|
81
76
|
end
|
77
|
+
return nil
|
78
|
+
end
|
82
79
|
|
83
|
-
|
84
|
-
|
85
|
-
|
80
|
+
# Allow a serializer instance to be used as a hash directly in a nested serializer config.
|
81
|
+
def [](key)
|
82
|
+
unless instance_variable_defined?(:@_nested_config)
|
83
|
+
@_nested_config = self.get_serializer_config
|
86
84
|
end
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
end
|
93
|
-
else
|
94
|
-
node.map! do |v|
|
95
|
-
self._resolve_serializer_config(node: v)
|
96
|
-
end
|
85
|
+
return @_nested_config[key]
|
86
|
+
end
|
87
|
+
def []=(key, value)
|
88
|
+
unless instance_variable_defined?(:@_nested_config)
|
89
|
+
@_nested_config = self.get_serializer_config
|
97
90
|
end
|
98
|
-
|
99
|
-
return node
|
91
|
+
return @_nested_config[key] = value
|
100
92
|
end
|
101
93
|
|
102
|
-
#
|
103
|
-
def
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
return
|
94
|
+
# Allow a serializer class to be used as a hash directly in a nested serializer config.
|
95
|
+
def self.[](key)
|
96
|
+
unless instance_variable_defined?(:@_nested_config)
|
97
|
+
@_nested_config = self.new.get_serializer_config
|
98
|
+
end
|
99
|
+
return @_nested_config[key]
|
108
100
|
end
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
if @object
|
113
|
-
@many = @object.respond_to?(:each) if @many.nil?
|
114
|
-
return @object.as_json(
|
115
|
-
self.get_resolved_serializer_config
|
116
|
-
)
|
101
|
+
def self.[]=(key, value)
|
102
|
+
unless instance_variable_defined?(:@_nested_config)
|
103
|
+
@_nested_config = self.new.get_serializer_config
|
117
104
|
end
|
118
|
-
return
|
105
|
+
return @_nested_config[key] = value
|
119
106
|
end
|
120
107
|
end
|
121
108
|
end
|