belt 0.5.0 → 0.5.1
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 +4 -4
- data/lib/belt/helpers/response.rb +11 -1
- data/lib/belt/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 78ab45dc8e21870d427c1c8db110678daaaa1af5fc0b21501058111e8f6fa77e
|
|
4
|
+
data.tar.gz: f56e7412f04395c43cf521fc955a90956f89d738fe346102f02fc39eb3d1a7db
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6a6383f82c559b3880df9f0f70e2e7b5cffe308547881bb866397193f7d3e9570770f4e7246871b3761903925ba04a7ba91aefcc836407472df0289e51309fb8
|
|
7
|
+
data.tar.gz: 4019aff2e5064a6eec27d2a31f2f92ba4e0bc3222bc636f8df38e9d9579d703ff0c097d9f8725ff6577d536917a347c64d7d6e2261e0fbf0d1b6eea3c28bff21
|
|
@@ -28,8 +28,18 @@ module Belt
|
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
# JSON success. Status accepts Integer or Symbol (:created, :ok, …).
|
|
31
|
+
#
|
|
32
|
+
# The body is deep-serialized the same way implicit assigns are, so handing
|
|
33
|
+
# it a model (or a hash/array containing models) produces real JSON instead
|
|
34
|
+
# of the model's #to_s. This keeps `success_response(thing: @thing)` and the
|
|
35
|
+
# implicit `@thing = ...` path consistent — without it, an explicit
|
|
36
|
+
# success_response silently falls through to `JSON.generate` on the bare
|
|
37
|
+
# object and emits "#<Thing:0x...>". Falls back to the raw body when the
|
|
38
|
+
# serializer isn't mixed in (e.g. the lambda handler, which only ever passes
|
|
39
|
+
# plain hashes).
|
|
31
40
|
def success_response(body, status_code = 200)
|
|
32
|
-
|
|
41
|
+
serialized = respond_to?(:serialize_for_response, true) ? serialize_for_response(body) : body
|
|
42
|
+
{ statusCode: resolve_status(status_code), headers: cors_headers, body: JSON.generate(serialized) }
|
|
33
43
|
end
|
|
34
44
|
|
|
35
45
|
# JSON error. Status accepts Integer or Symbol (:unprocessable_entity, :not_found, …).
|
data/lib/belt/version.rb
CHANGED