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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 161320de9187e5cbb240dc21f2e8e0022de852686cc5d462d60c8b80c2a58a21
4
- data.tar.gz: 65afaba8af50fa630e7f20d647de6531302352fce8e9b4de8e3589514e9923f4
3
+ metadata.gz: b8cff48c0ee5cfa89a5de1274be3303220345822527d05a090be207148a8b9b5
4
+ data.tar.gz: 60aa48e2d132770c406419b713582b0c7f88a5d833fbc48763a29ed8d58989b0
5
5
  SHA512:
6
- metadata.gz: 2e1e97f0bf724b0c6e279db38ffc38eb3a51cd5b1c2e0ec321efe7ae6ef5b364f9f862a1803a5ca0290b98c84b32123b3c5c053fd05301c595ae504ccc2673b7
7
- data.tar.gz: e3d0df2a1110d94026a3eac1a0a84bf6ab1002ef61a43ac8d8a38a7314cd1f8d9f6cf7faced23efd8d77d2b50f24ac2c0c1b017810a53849869e89738c2d50b2
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 = Hash.new do |_hash, key|
20
- raise(UndefinedNamedRoute, "Undefined named route: '#{key}'")
21
- end
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(request_builder.call(route_instance))
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).call(request_builder.call(route_instance))
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
- return push_to_scope(method.to_s.upcase, route_instance) if @scopes.size >= 1
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 + [:__instances]
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(*(found_scopes << :__instances)).detect do |route_instance|
130
- route_instance.match?(env)
131
- end
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)
@@ -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)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-http_router
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.31
4
+ version: 0.0.32
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henrique F. Teixeira