acrylic 0.1.0 → 0.1.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/bits.rb +4 -0
- data/lib/cascade.rb +18 -8
- data/lib/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: c7f964f398be355711d7cd892038190775d049259f99570198a41a9ddfb36161
|
|
4
|
+
data.tar.gz: 6536f6f878d30c39ef30ffdb05f2d7e55be715ffcd0fd17b03cce62dac2ba004
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3b3a59a768344665563753be56e7ff6d1dd577cb1d0787a2c46fd09e4d30b1228e7b57e8c26f916f6e252f9e831d9437fd2cd88faab6d3a6c94dda509a6165d8
|
|
7
|
+
data.tar.gz: aba291196d77af51d3ccb79575d8a5cdab4dee0dcfc5a5b36062b0a7e90c56d97632483aa7beb4696eed9e4fb99e0a627f0bb1c02191b0b0fbef873a01efb3cd
|
data/lib/bits.rb
CHANGED
data/lib/cascade.rb
CHANGED
|
@@ -41,7 +41,6 @@ module Acrylic
|
|
|
41
41
|
|
|
42
42
|
class Cascade
|
|
43
43
|
# returns a response based on the defined routes.
|
|
44
|
-
# if the response is empty, it shall be passed through Cascade.ServeError
|
|
45
44
|
def self.handle req
|
|
46
45
|
headers = {}
|
|
47
46
|
|
|
@@ -51,9 +50,12 @@ module Acrylic
|
|
|
51
50
|
|
|
52
51
|
res = route.call req
|
|
53
52
|
res = case true
|
|
54
|
-
when (res.
|
|
55
|
-
when (res.
|
|
56
|
-
when (res.is_a? Integer)
|
|
53
|
+
when (res.is_a? Rack::Response) then res
|
|
54
|
+
when (res.respond_to? :to_h) then res.to_h
|
|
55
|
+
when (res.is_a? Integer) then Rack::Response.new nil, res
|
|
56
|
+
when (res.is_a? String) then Rack::Response.new res
|
|
57
|
+
when (res.nil?) then next
|
|
58
|
+
else raise TypeError
|
|
57
59
|
end
|
|
58
60
|
|
|
59
61
|
# if the returned route has a body, return it. else, add its headers to the existing response.
|
|
@@ -61,12 +63,12 @@ module Acrylic
|
|
|
61
63
|
res.headers.merge! headers
|
|
62
64
|
return res
|
|
63
65
|
elsif res.is_a? Hash
|
|
64
|
-
headers.merge! res
|
|
66
|
+
headers.merge! res
|
|
65
67
|
end
|
|
66
68
|
end
|
|
67
69
|
|
|
68
70
|
# if no route returned a response, return a 404
|
|
69
|
-
return Rack::Response.new nil, 404
|
|
71
|
+
return Rack::Response.new nil, 404, headers
|
|
70
72
|
end
|
|
71
73
|
|
|
72
74
|
|
|
@@ -74,8 +76,16 @@ module Acrylic
|
|
|
74
76
|
req = Rack::Request.new env
|
|
75
77
|
|
|
76
78
|
res = handle req
|
|
77
|
-
|
|
78
|
-
|
|
79
|
+
# apply a series of transformations to the response
|
|
80
|
+
# unfortunately since Response is immutable we have to make a copy
|
|
81
|
+
# 1. if res is an error code, transform it into a full response with cascade/errors
|
|
82
|
+
body = res.body.fallback "" # (error_page res.status, req)
|
|
83
|
+
|
|
84
|
+
# 2. transform every header key of res into a string
|
|
85
|
+
headers = res.headers.map do |k, v| [k.to_s, v] end.to_h
|
|
86
|
+
|
|
87
|
+
p body
|
|
88
|
+
Rack::Response.new body, res.status, headers
|
|
79
89
|
end
|
|
80
90
|
end
|
|
81
91
|
end
|
data/lib/version.rb
CHANGED