rackr 0.0.58 → 0.0.60

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rackr/action.rb +14 -13
  3. data/lib/rackr/router.rb +15 -7
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5014c37c092dde5f043f96ff04bef8c53fdd9bc2df76233a23a0a8dd957be3f1
4
- data.tar.gz: 0cab424f6b8edb7f5e12ea2cfd05c7ac00be0df6c240affaacb57df2ca972040
3
+ metadata.gz: 56bb48ce2a38e77c44d84d7ee7537b144bff11293a6162750d497a392d5a2d6d
4
+ data.tar.gz: 1698e4e88202736612dfcb27d974f414eaf6dbafd62c40433fd33472b638e53e
5
5
  SHA512:
6
- metadata.gz: 7664d3fa655aea2dcbde6b9456bfd2e6ea0c2876cf47d060cc808519276b8e8e7244493360a2912449573fc422c15390a4afbe201c90c46311879065e9b4227a
7
- data.tar.gz: 1582549edba2bbca7dca30635106faed13cf28b01ef6941b31ebe745711494d91fab86ce3d4a76e115e56f9a5a141e73860a4f67ab3fc7b6836342d1a255363a
6
+ metadata.gz: 68e05e6048d84a6fdf937d6950f15b2d19d9a510e79aaa4a2bb6e375a19fd6b16788172b66e2b3752293eca89218600b319dfd146657e40fd893a619ba7a6083
7
+ data.tar.gz: 2d2cb75c23f21f1d317496e6cf066c74e20f7d13cdf199f754571ba03e77fcd5a72bf253f798fa1dd24a1c434614e8b790652bad8f53591fc374d5043ebfbdbf
data/lib/rackr/action.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'byebug'
4
3
  require 'erubi'
5
4
  require 'oj'
6
5
  require 'rack'
@@ -8,17 +7,17 @@ require 'rack'
8
7
  class Rackr
9
8
  module Action
10
9
  RENDER = {
11
- html: lambda do |val, **opts|
12
- [opts[:status] || 200, { 'content-type' => 'text/html' }.merge(opts[:headers] || {}), [val]]
10
+ html: lambda do |val, status: 200, headers: {}, html: nil|
11
+ [status, { 'content-type' => 'text/html', 'content-length' => val.bytesize.to_s }.merge(headers), [val]]
13
12
  end,
14
- text: lambda do |val, **opts|
15
- [opts[:status] || 200, { 'content-type' => 'text/plain' }.merge(opts[:headers] || {}), [val]]
13
+ text: lambda do |val, status: 200, headers: {}, text: nil|
14
+ [status, { 'content-type' => 'text/plain', 'content-length' => val.bytesize.to_s }.merge(headers), [val]]
16
15
  end,
17
- json: lambda do |val, **opts|
16
+ json: lambda do |val, status: 200, headers: {}, json: nil|
18
17
  val = Oj.dump(val, mode: :compat) unless val.is_a?(String)
19
- [opts[:status] || 200, { 'content-type' => 'application/json' }.merge(opts[:headers] || {}), [val]]
18
+ [status, { 'content-type' => 'application/json', 'content-length' => val.bytesize.to_s }.merge(headers), [val]]
20
19
  end
21
- }
20
+ }.freeze
22
21
 
23
22
  def self.included(base)
24
23
  base.class_eval do
@@ -34,7 +33,7 @@ class Rackr
34
33
  type = opts.keys.first
35
34
  content = opts[type]
36
35
 
37
- Rackr::Action::RENDER[type]&.(content, **opts) || _render_view(content, **opts)
36
+ Rackr::Action::RENDER[type]&.call(content, **opts) || _render_view(content, **opts)
38
37
  end
39
38
 
40
39
  def view_response(
@@ -93,7 +92,8 @@ class Rackr
93
92
  )
94
93
  end
95
94
 
96
- [status, { 'content-type' => 'text/html' }.merge(headers), [parsed_erb]]
95
+ [status, { 'content-type' => 'text/html', 'content-length' => parsed_erb.bytesize.to_s }.merge(headers),
96
+ [parsed_erb]]
97
97
  end
98
98
 
99
99
  def load_json(val)
@@ -103,7 +103,8 @@ class Rackr
103
103
  end
104
104
 
105
105
  def html_response(content = '', status: 200, headers: {})
106
- Rack::Response.new(content, status, { 'content-type' => 'text/html' }.merge(headers))
106
+ Rack::Response.new(content, status,
107
+ { 'content-type' => 'text/html', 'content-length' => content.bytesize.to_s }.merge(headers))
107
108
  end
108
109
 
109
110
  def json_response(content = {}, status: 200, headers: {})
@@ -111,7 +112,7 @@ class Rackr
111
112
  Rack::Response.new(
112
113
  content,
113
114
  status,
114
- { 'content-type' => 'application/json' }.merge(headers)
115
+ { 'content-type' => 'application/json', 'content-length' => content.bytesize.to_s }.merge(headers)
115
116
  )
116
117
  end
117
118
 
@@ -119,7 +120,7 @@ class Rackr
119
120
  Rack::Response.new(
120
121
  content,
121
122
  status,
122
- { 'content-type' => 'text/plain' }.merge(headers)
123
+ { 'content-type' => 'text/plain', 'content-length' => content.bytesize.to_s }.merge(headers)
123
124
  )
124
125
  end
125
126
 
data/lib/rackr/router.rb CHANGED
@@ -200,6 +200,12 @@ class Rackr
200
200
  end
201
201
 
202
202
  def match_route(request_method)
203
+ find_instance_in_scope = proc do |request_method, found_scopes|
204
+ @instance_routes[request_method].dig(
205
+ *(found_scopes + [:__instances])
206
+ )&.detect { |route_instance| route_instance.match?(@current_request_path_info) }
207
+ end
208
+
203
209
  last_tail = @splitted_request_path_info.drop(1)
204
210
  found_scopes = []
205
211
 
@@ -217,10 +223,7 @@ class Rackr
217
223
  instance_routes = @instance_routes[request_method].dig(*found_scopes)
218
224
  break
219
225
  elsif scope.start_with?(':')
220
- found_route = @instance_routes[request_method].dig(
221
- *(found_scopes + [:__instances])
222
- )&.detect { |route_instance| route_instance.match?(@current_request_path_info) }
223
-
226
+ found_route = find_instance_in_scope.(request_method, found_scopes)
224
227
  return found_route if found_route
225
228
 
226
229
  found_scopes << scope
@@ -230,9 +233,14 @@ class Rackr
230
233
  end
231
234
  end
232
235
 
233
- @instance_routes[request_method].dig(
234
- *(found_scopes + [:__instances])
235
- )&.detect { |route_instance| route_instance.match?(@current_request_path_info) }
236
+ result_route = find_instance_in_scope.(request_method, found_scopes)
237
+
238
+ if result_route == nil && !found_scopes.empty?
239
+ found_scopes.shift
240
+ result_route = find_instance_in_scope.(request_method, found_scopes)
241
+ end
242
+
243
+ result_route
236
244
  end
237
245
  end
238
246
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rackr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.58
4
+ version: 0.0.60
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henrique F. Teixeira
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-03-30 00:00:00.000000000 Z
10
+ date: 2025-10-11 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: erubi