rack-http_router 0.0.31 → 0.0.32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rack-http_router/action.rb +3 -2
- data/lib/rack-http_router/router.rb +17 -12
- data/lib/rack-http_router.rb +4 -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: b8cff48c0ee5cfa89a5de1274be3303220345822527d05a090be207148a8b9b5
|
4
|
+
data.tar.gz: 60aa48e2d132770c406419b713582b0c7f88a5d833fbc48763a29ed8d58989b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 26edd2abbaff17cab89906192014d14e151aca4edd6f6cd7f81d8e8e2ed674d129e728ccdd87ff8e7557ba88ae1323084dca434b8fd06643f501a476cf9a46fc
|
7
|
+
data.tar.gz: 6ce7a9c0fd92aaa12e9a7065c28594b20ac9af89634e34cef962b421ae4c702863c917ce1154c55f0854e4e0108ec2bdc52ef40ee6d00d66f923a4406fc60aca
|
@@ -9,11 +9,12 @@ module Rack
|
|
9
9
|
module Action
|
10
10
|
def self.included(base)
|
11
11
|
base.class_eval do
|
12
|
-
attr_reader :route, :config if self != Rack::HttpRouter
|
12
|
+
attr_reader :route, :config, :db if self != Rack::HttpRouter
|
13
13
|
|
14
|
-
def initialize(route, config)
|
14
|
+
def initialize(route: nil, config: nil)
|
15
15
|
@route = route
|
16
16
|
@config = config
|
17
|
+
@db = config[:db]
|
17
18
|
end
|
18
19
|
|
19
20
|
def view_response(a_path, a_view_params = {}, status: 200)
|
@@ -1,5 +1,3 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
require_relative 'router/route'
|
4
2
|
require_relative 'router/build_request'
|
5
3
|
|
@@ -16,9 +14,10 @@ module Rack
|
|
16
14
|
%w[GET POST DELETE PUT TRACE OPTIONS PATCH].each do |method|
|
17
15
|
@routes[method] = { __instances: [] }
|
18
16
|
end
|
19
|
-
@route =
|
20
|
-
|
21
|
-
|
17
|
+
@route =
|
18
|
+
Hash.new do |_hash, key|
|
19
|
+
raise(UndefinedNamedRoute, "Undefined named route: '#{key}'")
|
20
|
+
end
|
22
21
|
@config = config
|
23
22
|
@scopes = []
|
24
23
|
@error = proc { |_req, e| raise e }
|
@@ -34,11 +33,14 @@ module Rack
|
|
34
33
|
return render_not_found(request_builder.call) if route_instance.nil?
|
35
34
|
|
36
35
|
if route_instance.endpoint.respond_to?(:call)
|
37
|
-
return route_instance.endpoint.call(
|
36
|
+
return route_instance.endpoint.call(
|
37
|
+
request_builder.call(route_instance)
|
38
|
+
)
|
38
39
|
end
|
39
40
|
|
40
41
|
if route_instance.endpoint.include?(Rack::HttpRouter::Action)
|
41
|
-
return route_instance.endpoint.new(@route, @config)
|
42
|
+
return route_instance.endpoint.new(route: @route, config: @config)
|
43
|
+
.call(request_builder.call(route_instance))
|
42
44
|
end
|
43
45
|
|
44
46
|
route_instance.endpoint.new.call(request_builder.call(route_instance))
|
@@ -54,7 +56,9 @@ module Rack
|
|
54
56
|
|
55
57
|
route_instance = Route.new(path_with_scopes, endpoint)
|
56
58
|
|
57
|
-
|
59
|
+
if @scopes.size >= 1
|
60
|
+
return push_to_scope(method.to_s.upcase, route_instance)
|
61
|
+
end
|
58
62
|
|
59
63
|
@routes[method.to_s.upcase][:__instances].push(route_instance)
|
60
64
|
end
|
@@ -78,7 +82,7 @@ module Rack
|
|
78
82
|
private
|
79
83
|
|
80
84
|
def push_to_scope(method, route_instance)
|
81
|
-
scopes_with_slash = @scopes + [
|
85
|
+
scopes_with_slash = @scopes + %i[__instances]
|
82
86
|
push_it(@routes[method], *scopes_with_slash, route_instance)
|
83
87
|
end
|
84
88
|
|
@@ -126,9 +130,10 @@ module Rack
|
|
126
130
|
end
|
127
131
|
|
128
132
|
if tail.empty? || found_scopes == []
|
129
|
-
return @routes[env['REQUEST_METHOD']].dig(
|
130
|
-
|
131
|
-
|
133
|
+
return @routes[env['REQUEST_METHOD']].dig(
|
134
|
+
*(found_scopes << :__instances)
|
135
|
+
)
|
136
|
+
.detect { |route_instance| route_instance.match?(env) }
|
132
137
|
end
|
133
138
|
|
134
139
|
match_route(env, tail, found_scopes)
|
data/lib/rack-http_router.rb
CHANGED
@@ -8,7 +8,6 @@ module Rack
|
|
8
8
|
include Action
|
9
9
|
|
10
10
|
def initialize(config = {})
|
11
|
-
p "oi"
|
12
11
|
@router = Router.new(config)
|
13
12
|
end
|
14
13
|
|
@@ -26,6 +25,10 @@ module Rack
|
|
26
25
|
@router.config
|
27
26
|
end
|
28
27
|
|
28
|
+
def db
|
29
|
+
@router.config[:db]
|
30
|
+
end
|
31
|
+
|
29
32
|
def scope(name, &block)
|
30
33
|
@router.append_scope(name)
|
31
34
|
instance_eval(&block)
|