rackr 0.0.46 → 0.0.48
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/rackr/router.rb +14 -16
- data/lib/rackr.rb +13 -4
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 17ea0ba90cd0ee285862c06535ce35a2965a475e0e46994057c40af7631fd082
|
4
|
+
data.tar.gz: 858b1c9b70af9a250ecf46cb7bc7020735bccf6d2c9da9948dc2b60038ce939d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e3ac8005daa702a46140afeec59bb7cd2f339c6a12dce1468ca8e3c4b447b68ac00068b76807594365db54bc32a0d7ca219d42389098c0fac7d3b53346eb4856
|
7
|
+
data.tar.gz: 57059e5130445514fc26f7972ed9c972835798e666a262372b2f5e1797e938ba01aa5a68649ebcff431afa149e2069b7646212eb6a4ba1a939e35e347b2aca2f
|
data/lib/rackr/router.rb
CHANGED
@@ -14,18 +14,20 @@ class Rackr
|
|
14
14
|
%w[GET POST DELETE PUT TRACE OPTIONS PATCH].each do |method|
|
15
15
|
@instance_routes[method] = { __instances: [] }
|
16
16
|
end
|
17
|
-
|
18
|
-
|
17
|
+
http_methods = HTTP_METHODS.map { |m| m.downcase.to_sym }
|
18
|
+
@routes = Struct.new(*http_methods).new
|
19
|
+
http_methods.each do |method|
|
20
|
+
@routes.send("#{method}=", Hash.new do |_hash, key|
|
19
21
|
raise(Errors::UndefinedNamedRouteError, "Undefined named route: '#{key}'")
|
20
|
-
end
|
22
|
+
end)
|
23
|
+
end
|
24
|
+
|
21
25
|
@config = config
|
22
26
|
@branches = []
|
23
27
|
@befores = ensure_array(before)
|
24
28
|
@branches_befores = {}
|
25
29
|
@afters = ensure_array(after)
|
26
30
|
@branches_afters = {}
|
27
|
-
@nameds_as = []
|
28
|
-
@branches_named_as = {}
|
29
31
|
@error = proc { |_req, e| raise e }
|
30
32
|
@not_found = proc { [404, {}, ['Not found']] }
|
31
33
|
@splitted_request_path = []
|
@@ -81,7 +83,7 @@ class Rackr
|
|
81
83
|
method = :get if method == :head
|
82
84
|
|
83
85
|
path_with_branches = "/#{@branches.join('/')}#{put_path_slash(path)}"
|
84
|
-
add_named_route(path_with_branches, as)
|
86
|
+
add_named_route(method, path_with_branches, as)
|
85
87
|
|
86
88
|
route_instance =
|
87
89
|
Route.new(
|
@@ -108,9 +110,8 @@ class Rackr
|
|
108
110
|
@error = endpoint
|
109
111
|
end
|
110
112
|
|
111
|
-
def append_branch(name, branch_befores: [], branch_afters: []
|
113
|
+
def append_branch(name, branch_befores: [], branch_afters: [])
|
112
114
|
Errors.check_branch_name(name)
|
113
|
-
Errors.check_as(as, @branches.join('/'))
|
114
115
|
Errors.check_callbacks(branch_befores, name)
|
115
116
|
Errors.check_callbacks(branch_afters, name)
|
116
117
|
|
@@ -125,15 +126,11 @@ class Rackr
|
|
125
126
|
branch_afters = ensure_array(branch_afters)
|
126
127
|
@afters.concat(branch_afters)
|
127
128
|
@branches_afters[name] = branch_afters
|
128
|
-
|
129
|
-
@nameds_as.push(as)
|
130
|
-
@branches_named_as[name] = as
|
131
129
|
end
|
132
130
|
|
133
131
|
def clear_last_branch
|
134
132
|
@befores -= @branches_befores[@branches.last]
|
135
133
|
@afters -= @branches_afters[@branches.last]
|
136
|
-
@nameds_as -= [@branches_named_as[@branches.last]]
|
137
134
|
@branches = @branches.first(@branches.size - 1)
|
138
135
|
end
|
139
136
|
|
@@ -156,11 +153,12 @@ class Rackr
|
|
156
153
|
[list]
|
157
154
|
end
|
158
155
|
|
159
|
-
def add_named_route(path_with_branches, as)
|
160
|
-
|
161
|
-
return
|
156
|
+
def add_named_route(method, path_with_branches, as)
|
157
|
+
return @routes.send(method.downcase)[:root] = path_with_branches if path_with_branches == '/'
|
158
|
+
return @routes.send(method.downcase)[as] = path_with_branches unless as.nil?
|
162
159
|
|
163
|
-
|
160
|
+
key = path_with_branches.sub("/","").gsub(":","").gsub("/","_")
|
161
|
+
@routes.send(method.downcase)["#{key}".to_sym] = path_with_branches
|
164
162
|
end
|
165
163
|
|
166
164
|
def push_to_branch(method, route_instance)
|
data/lib/rackr.rb
CHANGED
@@ -7,6 +7,8 @@ require_relative 'rackr/callback'
|
|
7
7
|
class Rackr
|
8
8
|
class NotFound < StandardError; end
|
9
9
|
|
10
|
+
HTTP_METHODS = %w[GET POST DELETE PUT TRACE OPTIONS PATCH]
|
11
|
+
|
10
12
|
include Action
|
11
13
|
|
12
14
|
def initialize(config = {}, before: [], after: [])
|
@@ -31,12 +33,11 @@ class Rackr
|
|
31
33
|
@router.config[:db]
|
32
34
|
end
|
33
35
|
|
34
|
-
def r(name, before: [], after: [],
|
36
|
+
def r(name, before: [], after: [], &block)
|
35
37
|
@router.append_branch(
|
36
38
|
name,
|
37
39
|
branch_befores: before,
|
38
40
|
branch_afters: after,
|
39
|
-
as: as
|
40
41
|
)
|
41
42
|
instance_eval(&block)
|
42
43
|
|
@@ -59,8 +60,11 @@ class Rackr
|
|
59
60
|
end
|
60
61
|
end
|
61
62
|
|
62
|
-
|
63
|
-
define_method(http_method.downcase.to_sym) do
|
63
|
+
HTTP_METHODS.each do |http_method|
|
64
|
+
define_method(http_method.downcase.to_sym) do |*params, before: [], after: [], as: nil, &block|
|
65
|
+
path = params[0] || ''
|
66
|
+
endpoint = params[1] || ''
|
67
|
+
|
64
68
|
if block.respond_to?(:call)
|
65
69
|
@router.add(
|
66
70
|
http_method,
|
@@ -71,6 +75,11 @@ class Rackr
|
|
71
75
|
route_afters: after
|
72
76
|
)
|
73
77
|
else
|
78
|
+
if path.is_a?(Module) && path.include?(Action)
|
79
|
+
endpoint = path
|
80
|
+
path = ''
|
81
|
+
end
|
82
|
+
|
74
83
|
@router.add(
|
75
84
|
http_method,
|
76
85
|
path,
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rackr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.48
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Henrique F. Teixeira
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: erubi
|
@@ -75,7 +75,7 @@ homepage: https://github.com/henrique-ft/rackr
|
|
75
75
|
licenses:
|
76
76
|
- MIT
|
77
77
|
metadata: {}
|
78
|
-
post_install_message:
|
78
|
+
post_install_message:
|
79
79
|
rdoc_options: []
|
80
80
|
require_paths:
|
81
81
|
- lib
|
@@ -90,8 +90,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
90
|
- !ruby/object:Gem::Version
|
91
91
|
version: '0'
|
92
92
|
requirements: []
|
93
|
-
rubygems_version: 3.
|
94
|
-
signing_key:
|
93
|
+
rubygems_version: 3.5.16
|
94
|
+
signing_key:
|
95
95
|
specification_version: 4
|
96
96
|
summary: A complete http router solution that fit well with pure rack apps.
|
97
97
|
test_files: []
|