rack-http_router 0.0.1 → 0.0.31

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: 5575554ab4629e83f2524f4fe47ff58963909b658452a3646457da97c378d744
4
- data.tar.gz: a409c6bdd4df80abba1206e79a4adefd05d75142cbdd775e1418de33bee23ea7
3
+ metadata.gz: 161320de9187e5cbb240dc21f2e8e0022de852686cc5d462d60c8b80c2a58a21
4
+ data.tar.gz: 65afaba8af50fa630e7f20d647de6531302352fce8e9b4de8e3589514e9923f4
5
5
  SHA512:
6
- metadata.gz: 13eac202ecb0c2c1bfc1287298cfa45ae202949e6738c8dec1689e8a674a0d8b5b60438a8d990e1dd77159eb75cfea3a90ddd60ab30376aa6f35e21bbc4f1c51
7
- data.tar.gz: 8a43962f554a10aef1696ff990cb5096b1a211f3e8f28199b52b7ad36a6c079ad3bf070f51ad0710aec284fdb0156ff50ae7dfcfb0b6e2951cc7f0c17046de17
6
+ metadata.gz: 2e1e97f0bf724b0c6e279db38ffc38eb3a51cd5b1c2e0ec321efe7ae6ef5b364f9f862a1803a5ca0290b98c84b32123b3c5c053fd05301c595ae504ccc2673b7
7
+ data.tar.gz: e3d0df2a1110d94026a3eac1a0a84bf6ab1002ef61a43ac8d8a38a7314cd1f8d9f6cf7faced23efd8d77d2b50f24ac2c0c1b017810a53849869e89738c2d50b2
@@ -9,10 +9,11 @@ module Rack
9
9
  module Action
10
10
  def self.included(base)
11
11
  base.class_eval do
12
- attr_reader :route if self != Rack::HttpRouter
12
+ attr_reader :route, :config if self != Rack::HttpRouter
13
13
 
14
- def initialize(route)
14
+ def initialize(route, config)
15
15
  @route = route
16
+ @config = config
16
17
  end
17
18
 
18
19
  def view_response(a_path, a_view_params = {}, status: 200)
@@ -63,6 +64,10 @@ module Rack
63
64
  Rack::HttpRouter::Action.erb(path, view_params)
64
65
  end
65
66
 
67
+ def redirect_response(url)
68
+ Rack::HttpRouter::Action.redirect_response(url)
69
+ end
70
+
66
71
  def redirect_to(url)
67
72
  Rack::HttpRouter::Action.redirect_to(url)
68
73
  end
@@ -143,6 +148,14 @@ module Rack
143
148
  eval(Erubi::Engine.new(::File.read("#{path}.html.erb")).src)
144
149
  end
145
150
 
151
+ def redirect_response(url)
152
+ Rack::Response.new(
153
+ nil,
154
+ 302,
155
+ { 'Location' => url }
156
+ )
157
+ end
158
+
146
159
  def redirect_to(url)
147
160
  [302, { 'Location' => url }, []]
148
161
  end
@@ -9,9 +9,9 @@ module Rack
9
9
  class UndefinedNamedRoute < StandardError; end
10
10
 
11
11
  attr_writer :not_found
12
- attr_reader :route
12
+ attr_reader :route, :config
13
13
 
14
- def initialize
14
+ def initialize(config = {})
15
15
  @routes = {}
16
16
  %w[GET POST DELETE PUT TRACE OPTIONS PATCH].each do |method|
17
17
  @routes[method] = { __instances: [] }
@@ -19,6 +19,7 @@ module Rack
19
19
  @route = Hash.new do |_hash, key|
20
20
  raise(UndefinedNamedRoute, "Undefined named route: '#{key}'")
21
21
  end
22
+ @config = config
22
23
  @scopes = []
23
24
  @error = proc { |_req, e| raise e }
24
25
  @not_found = proc { [404, {}, ['Not found']] }
@@ -37,7 +38,7 @@ module Rack
37
38
  end
38
39
 
39
40
  if route_instance.endpoint.include?(Rack::HttpRouter::Action)
40
- return route_instance.endpoint.new(@route).call(request_builder.call(route_instance))
41
+ return route_instance.endpoint.new(@route, @config).call(request_builder.call(route_instance))
41
42
  end
42
43
 
43
44
  route_instance.endpoint.new.call(request_builder.call(route_instance))
@@ -7,8 +7,9 @@ module Rack
7
7
  class HttpRouter
8
8
  include Action
9
9
 
10
- def initialize(router: Router.new)
11
- @router = router
10
+ def initialize(config = {})
11
+ p "oi"
12
+ @router = Router.new(config)
12
13
  end
13
14
 
14
15
  def call(&block)
@@ -21,6 +22,10 @@ module Rack
21
22
  @router.route
22
23
  end
23
24
 
25
+ def config
26
+ @router.config
27
+ end
28
+
24
29
  def scope(name, &block)
25
30
  @router.append_scope(name)
26
31
  instance_eval(&block)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-http_router
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.31
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henrique F. Teixeira
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-07-22 00:00:00.000000000 Z
11
+ date: 2023-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: erubi
@@ -55,7 +55,7 @@ files:
55
55
  - lib/rack-http_router/router.rb
56
56
  - lib/rack-http_router/router/build_request.rb
57
57
  - lib/rack-http_router/router/route.rb
58
- homepage: https://github.com/henriquefernandez/rack-http_router
58
+ homepage: https://github.com/henrique-ft/rack-http_router
59
59
  licenses:
60
60
  - MIT
61
61
  metadata: {}