ratalada 2.0.1 → 2.1.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6d020d5668bf545f9babae240d0aed21f6fea5edc6b1f157b95403b3f29ae1d9
4
- data.tar.gz: 706e4faeaa540a52e8d71de16a00332828ce81808b43d0bde4d9d84d785fa4be
3
+ metadata.gz: d301916f1d7cbe6abcdffafc8cd2bee59c3fa4505db6d47ec3fde43de79ed19b
4
+ data.tar.gz: 265347175e831b2a644a2189551849c33068caf0829adce126249a094808336b
5
5
  SHA512:
6
- metadata.gz: 651da70b2bbca675a448cf91f247c00ac9f74be3c2a871a9cd1978cc615444df0b685edd048cd8e28b16a3b2d1fb9750ffd707818ba57025e3fe07d7044b81c4
7
- data.tar.gz: 302f09422321099f66e839d8274251269e3b828cedb7edbc6bb1c1fa90fa6cfe6dc61ef1f64945477bd6cd3d90aa4396829be9bdd908d14c651eef7646ae99b4
6
+ metadata.gz: fe1cfb2a6b815e55ac3f5d888b4a259b954429900ba3a70f6d65902d650f13fd9929807455b0d43808cba949ce170d71a974d435c9da0b1f50aabddcfdbe0bd8
7
+ data.tar.gz: 41f61e2e389adb79e84a5df10ae9b1e95cbfb03099c7908dcf7cd6a5ea4e2189db9bf3ae2df658c12453ec6f8c7ab1328ad7b25a8c319798f4eed0ead55df591
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ratalada
4
- VERSION = "2.0.1"
4
+ VERSION = "2.1.0"
5
5
  end
data/lib/ratalada.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "rack"
3
4
  require_relative "ratalada/version"
4
5
 
5
6
  module Ratalada
@@ -35,18 +36,22 @@ module Ratalada
35
36
  end
36
37
  end
37
38
 
38
- # Wraps the Rack env with just enough sugar to pattern match on.
39
- class Request
40
- attr_reader :env
41
-
42
- def initialize(env)
43
- @env = env
44
- end
45
-
39
+ # Rack::Request plus just enough sugar to pattern match on, so everything
40
+ # rack already parses — params, cookies, headers, host, ip, session — comes
41
+ # along for free.
42
+ class Request < ::Rack::Request
43
+ # #path is PATH_INFO, not rack's own #path (SCRIPT_NAME + PATH_INFO):
44
+ # mounted under a `map`, routing here should match the path within this
45
+ # app, not the one the outer app was reached by.
46
46
  def verb = env["REQUEST_METHOD"]
47
47
  def path = env["PATH_INFO"]
48
48
  def query = env["QUERY_STRING"]
49
- def body = @body ||= env["rack.input"]&.read
49
+
50
+ # Rack's own #body is the rack.input stream; this is the whole of it as a
51
+ # String, memoized because rack 3 input reads once and does not rewind.
52
+ # To stream instead, chunk through #read and never touch #body.
53
+ def body = @body ||= read
54
+ def read(...) = env["rack.input"].read(...)
50
55
 
51
56
  # Enables `in ["GET", "/"]`
52
57
  def deconstruct = [verb, path]
@@ -62,6 +67,20 @@ module Ratalada
62
67
  # triplet. No match (nil, or a fall-through `case ... in`) means 404.
63
68
  module Routes
64
69
  def self.build(block)
70
+ # Rack::Utils' helpers (escape_html, parse_query, set_cookie_header,
71
+ # ...) are callable unqualified inside the block, with no include at the
72
+ # call site and without instance_exec'ing it — self and ivars in the
73
+ # block stay the caller's. The include goes on the singleton of the
74
+ # object the block was written in, so nothing else in the process sees
75
+ # it, and since Rack::Utils is module_function'd they arrive as private
76
+ # methods that a receiver's own escape/status_code still overrides.
77
+ # ArgumentError: a C-level proc, which has no binding (&:symbol, #curry).
78
+ # TypeError: a frozen receiver. Neither can take the include; skip it.
79
+ begin
80
+ block.binding.receiver.singleton_class.include(::Rack::Utils)
81
+ rescue ArgumentError, TypeError
82
+ nil
83
+ end
65
84
  App.new(block)
66
85
  end
67
86
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ratalada
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan K
@@ -9,6 +9,20 @@ bindir: exe
9
9
  cert_chain: []
10
10
  date: 1980-01-01 00:00:00.000000000 Z
11
11
  dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: rack
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '3.0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '3.0'
12
26
  - !ruby/object:Gem::Dependency
13
27
  name: minitest
14
28
  requirement: !ruby/object:Gem::Requirement