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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 48c497f985b09a99774510f33863b653e0ae270c16813435c7a79918a0e77b03
4
- data.tar.gz: d8e303aa23f6fa5e59b3f4485d4879d6bca7fc1f9d36a63255e9fcb3abbbb30d
3
+ metadata.gz: 9db130a09c0e3b6772f5ca690d078e5ac7896f29dc397bd2f9f33207d630271c
4
+ data.tar.gz: 4bfa562d22d044a730fb26b2b933c5cd92a29ca96998c02445450267edb79b5e
5
5
  SHA512:
6
- metadata.gz: fba5c188d864b03c5d492a35e3710fbc79fe1dea1dc7317846a5ebd5ae95aa1db3886fe90632feeb9176c4863cdaa9e4fdef1b754d490c701ff129c3984cdd19
7
- data.tar.gz: 50cf64a803dfc332bdcc5b0f10b9a671c51993c930e67f4e8cb8474adb4bd7c3ac9e20325fc6ce12f223e381b6b845ab707f969bfe727fedef01e41fecc58d27
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 *wargs, **kwargs, &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 *wargs, **kwargs, &proc
4
- route *wargs, **kwargs do |conf, req|
5
- data = JSON.load(req.body).structize
6
- proc.call conf, req, data
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
@@ -1,8 +1,8 @@
1
1
  module Acrylic
2
2
  class Version
3
3
  MAJOR = 0
4
- MINOR = 6
5
- HOTFIX = 4
4
+ MINOR = 7
5
+ HOTFIX = 0
6
6
 
7
7
  def self.semver
8
8
  "#{MAJOR}.#{MINOR}.#{HOTFIX}"
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.6.4
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-16 00:00:00.000000000 Z
10
+ date: 2026-01-26 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: rack