acrylic 0.2.3 → 0.3.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/anubis.rb +0 -0
- data/lib/bits.rb +22 -0
- data/lib/cascade.rb +6 -6
- data/lib/version.rb +2 -2
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 87316921f14a552574ac7299c3fcd42f4d565b269ab2fc4dd773f02fb2eafae1
|
|
4
|
+
data.tar.gz: b1292abed88054f9ff4193da0356c7916decfb5a6546cc666fc271eb5e6f1947
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f38adf01be3856e7fa39112497f57cb2ac7bbdd560a0739fd50d72bca25fa3c84a570dc116db0362c21955eec1f8b7cf2e907698e315e5cd17d1a9acb6c9a329
|
|
7
|
+
data.tar.gz: 8f8c37880764223637dc5a31913a29323d912b8dfa0e41a83612ff2d13bc43b4721f8ca7ebcfe4b8846b885802e8d9ab08ef5e146265a968a67588eca0424a67
|
data/lib/anubis.rb
ADDED
|
File without changes
|
data/lib/bits.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
require 'ostruct'
|
|
2
|
+
|
|
1
3
|
class Object
|
|
2
4
|
def containerize
|
|
3
5
|
if self.is_a? Array then self else [self].compact end
|
|
@@ -18,4 +20,24 @@ class Hash
|
|
|
18
20
|
def self.from_keys keys, value = nil
|
|
19
21
|
keys.map do |k| [k, value] end.to_h
|
|
20
22
|
end
|
|
23
|
+
|
|
24
|
+
def self.from_values values
|
|
25
|
+
k = -1
|
|
26
|
+
values.map do |v|
|
|
27
|
+
k += 1
|
|
28
|
+
[k, v]
|
|
29
|
+
end.to_h
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# recursively converts hash to ostruct.
|
|
33
|
+
def structize
|
|
34
|
+
OpenStruct.new map do |k, v| end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
class Array
|
|
39
|
+
# like sort by, but sorts entries with same index
|
|
40
|
+
def sort_by_stable &proc
|
|
41
|
+
Hash.from_values(self).sort_by do |k, v| [proc.call(v), k] end.to_h.values
|
|
42
|
+
end
|
|
21
43
|
end
|
data/lib/cascade.rb
CHANGED
|
@@ -5,17 +5,15 @@ module Acrylic
|
|
|
5
5
|
ROUTES = []
|
|
6
6
|
|
|
7
7
|
class Route
|
|
8
|
-
# list of HTTP verbs the request will be matched against.
|
|
9
|
-
attr_reader :verbs
|
|
10
|
-
|
|
11
8
|
# list of path rules (wildcards or regexps)
|
|
12
9
|
attr_reader :paths
|
|
10
|
+
attr_reader :priority
|
|
13
11
|
|
|
14
12
|
def initialize args, handler
|
|
15
13
|
@handler = handler
|
|
16
14
|
|
|
15
|
+
@priority = args[:priority] or 0 # defualt priority
|
|
17
16
|
@paths = args[:path].containerize
|
|
18
|
-
@verbs = (args[:verb] or :GET).containerize.map do |verb| verb.downcase.to_sym end
|
|
19
17
|
end
|
|
20
18
|
|
|
21
19
|
# transforms a rule from string (e.g. "/User/<id>") to wildcard
|
|
@@ -50,7 +48,7 @@ module Acrylic
|
|
|
50
48
|
|
|
51
49
|
def match? req
|
|
52
50
|
# match against paths
|
|
53
|
-
(path_match? req.path)
|
|
51
|
+
(path_match? req.path)
|
|
54
52
|
end
|
|
55
53
|
|
|
56
54
|
def call req, *args
|
|
@@ -66,8 +64,10 @@ module Acrylic
|
|
|
66
64
|
config = OpenStruct.new
|
|
67
65
|
|
|
68
66
|
# loop through all the routes to find a final one
|
|
69
|
-
|
|
67
|
+
# (and sort them by priority descending and index)
|
|
68
|
+
Acrylic::ROUTES.sort_by_stable do |route| route.priority end.each do |route|
|
|
70
69
|
next unless route.match? req
|
|
70
|
+
puts route.priority
|
|
71
71
|
|
|
72
72
|
res = route.call config, req, *(route.args_for_path req.path)
|
|
73
73
|
|
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.3.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-03 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: rack
|
|
@@ -62,6 +62,7 @@ files:
|
|
|
62
62
|
- README.md
|
|
63
63
|
- VERSION.md
|
|
64
64
|
- lib/acrylic.rb
|
|
65
|
+
- lib/anubis.rb
|
|
65
66
|
- lib/bits.rb
|
|
66
67
|
- lib/cascade.rb
|
|
67
68
|
- lib/cascade/errors.rb
|