acrylic 0.6.4 → 0.7.0
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/cascade.rb +6 -5
- data/lib/palette.rb +12 -4
- data/lib/version.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9db130a09c0e3b6772f5ca690d078e5ac7896f29dc397bd2f9f33207d630271c
|
|
4
|
+
data.tar.gz: 4bfa562d22d044a730fb26b2b933c5cd92a29ca96998c02445450267edb79b5e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: df53adf6ed2e60520d26392b2e1a86eb47af6b1c1f50f13d5d448a0e9273a3d70eafb0cf637a58a4338f56c50a91abcce9c5ec24c63b9f9b59b3a2bfd3ce4e78
|
|
7
|
+
data.tar.gz: f4b10ca062b5005324f25768df9dfaa3c50a46d8202102b3295fc357d7c177d99eecb13881cc0137995a41391db368f5ad091dd8401920e5bcdb1aac145f7509
|
data/lib/cascade.rb
CHANGED
|
@@ -14,7 +14,7 @@ module Acrylic
|
|
|
14
14
|
@handler = handler
|
|
15
15
|
@name = args[:name]
|
|
16
16
|
@priority = args[:priority] || 0
|
|
17
|
-
@paths = args[:path].containerize
|
|
17
|
+
@paths = (args[:path] or '/**').containerize
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
# transforms a rule from string (e.g. "/User/<id>") to wildcard
|
|
@@ -28,7 +28,7 @@ module Acrylic
|
|
|
28
28
|
@paths.each do |rule|
|
|
29
29
|
if ((rule.is_a? Regexp) and (rule.match? path)) \
|
|
30
30
|
or ((rule.respond_to? :call) and (rule.call path)) \
|
|
31
|
-
or ((rule.respond_to? :to_s) and (File.fnmatch make_into_wildcard(rule.to_s), path, 0b11000))
|
|
31
|
+
or ((rule.respond_to? :to_s) and (File.fnmatch? make_into_wildcard(rule.to_s), path, 0b11000))
|
|
32
32
|
then return rule end
|
|
33
33
|
end
|
|
34
34
|
|
|
@@ -76,11 +76,13 @@ module Acrylic
|
|
|
76
76
|
res = case true
|
|
77
77
|
when (res.is_a? Exception) then return Rack::Response.new (error_body 500, req, config, res), 500 # also give it the exception
|
|
78
78
|
when (res.is_a? Rack::Response) then res
|
|
79
|
+
when (res.respond_to? :to_a) then Rack::Response.new res
|
|
79
80
|
when (res.respond_to? :to_h) then res.to_h
|
|
80
81
|
when (res.is_a? Integer) then Rack::Response.new nil, res
|
|
82
|
+
when (res.respond_to? :to_path) then Rack::Response.new res
|
|
81
83
|
when (res.is_a? String) then Rack::Response.new res
|
|
82
84
|
when (res.nil?) then next
|
|
83
|
-
else raise TypeError
|
|
85
|
+
else raise TypeError.new("expected response, hash, integer, or string for response; got #{res}")
|
|
84
86
|
end
|
|
85
87
|
|
|
86
88
|
# if the returned route has a body, return it. else, add its headers to the existing response.
|
|
@@ -121,8 +123,7 @@ def route_with_name name
|
|
|
121
123
|
Acrylic::ROUTES.find { |route| route.name = name }
|
|
122
124
|
end
|
|
123
125
|
|
|
124
|
-
def route
|
|
125
|
-
args = (Hash.from_keys wargs).merge kwargs
|
|
126
|
+
def route **args, &route
|
|
126
127
|
Acrylic::ROUTES << (Acrylic::Route.new args, Proc.new(&route))
|
|
127
128
|
end
|
|
128
129
|
|
data/lib/palette.rb
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
# palette: a collection of methods (mostly for cascade) to make tedious and repetitive tasks
|
|
2
2
|
|
|
3
|
-
def json_route
|
|
4
|
-
route
|
|
5
|
-
data = JSON.load(req.body).structize
|
|
6
|
-
proc.call
|
|
3
|
+
def json_route **kwargs, &proc
|
|
4
|
+
route **kwargs do |conf, req|
|
|
5
|
+
data = JSON.load(req.body).structize rescue nil
|
|
6
|
+
proc.call(conf, req, data).to_json
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def static_route from, to, **kwargs
|
|
11
|
+
route **kwargs do |conf, req|
|
|
12
|
+
if req.path.start_with? to
|
|
13
|
+
Pathname.new(from + req.path.delete_prefix(to))
|
|
14
|
+
end
|
|
7
15
|
end
|
|
8
16
|
end
|
data/lib/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: acrylic
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.7.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- fmixolydian
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date: 2026-01-
|
|
10
|
+
date: 2026-01-26 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: rack
|