rack-app 8.1.0 → 9.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/rack/app/constants.rb +12 -11
- data/lib/rack/app/handlers.rb +17 -0
- data/lib/rack/app/hook.rb +14 -0
- data/lib/rack/app/instance_methods/core.rb +5 -1
- data/lib/rack/app/middlewares/configuration.rb +16 -9
- data/lib/rack/app/middlewares/hooks/base.rb +3 -3
- data/lib/rack/app/singleton_methods/hooks.rb +6 -2
- data/lib/rack/app.rb +3 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d6895f4a62b9e5714c7f31f100ffdd705dfb3af6d4e73f823b99fca71526602f
|
4
|
+
data.tar.gz: 8377e012c98cc1010ffb9af5cca8ae46d79d9bb4dd8ad80799eb2e02fef2aff9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 21c9910e0cea0f738cab34e536cd9c180ef29f611ceaa54cb1909feddb6e0749ad6791bec4ef2a97d17d5da2267d28371773d77e70b4c8c813d79ac776bc836b
|
7
|
+
data.tar.gz: 2ad9151b5b2570acab5b52631ec8298ac48182fc4869075ba30a42f706f666f5580143fb3fbae7332145431cee1d08e2df87538df46337f96ce1699c7a88be83
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
9.0.0
|
data/lib/rack/app/constants.rb
CHANGED
@@ -11,17 +11,17 @@ module Rack::App::Constants
|
|
11
11
|
module HTTP
|
12
12
|
|
13
13
|
module METHOD
|
14
|
-
ANY
|
15
|
-
GET
|
16
|
-
POST
|
17
|
-
PUT
|
18
|
-
PATCH
|
19
|
-
DELETE
|
20
|
-
HEAD
|
14
|
+
ANY = 'ANY'.freeze
|
15
|
+
GET = 'GET'.freeze
|
16
|
+
POST = 'POST'.freeze
|
17
|
+
PUT = 'PUT'.freeze
|
18
|
+
PATCH = 'PATCH'.freeze
|
19
|
+
DELETE = 'DELETE'.freeze
|
20
|
+
HEAD = 'HEAD'.freeze
|
21
21
|
OPTIONS = 'OPTIONS'.freeze
|
22
|
-
LINK
|
23
|
-
UNLINK
|
24
|
-
TRACE
|
22
|
+
LINK = 'LINK'.freeze
|
23
|
+
UNLINK = 'UNLINK'.freeze
|
24
|
+
TRACE = 'TRACE'.freeze
|
25
25
|
end
|
26
26
|
|
27
27
|
METHODS = (METHOD.constants - [:ANY]).map(&:to_s).freeze
|
@@ -40,6 +40,7 @@ module Rack::App::Constants
|
|
40
40
|
|
41
41
|
ROUTER = 'rack-app.router'.freeze
|
42
42
|
HANDLER = 'rack-app.handler'.freeze
|
43
|
+
HANDLERS = 'rack-app.handlers'.freeze
|
43
44
|
EXTNAME = 'rack-app.extname'.freeze
|
44
45
|
SERIALIZER = 'rack-app.serializer'.freeze
|
45
46
|
CONTENT_TYPE = 'CONTENT_TYPE'.freeze
|
@@ -49,7 +50,7 @@ module Rack::App::Constants
|
|
49
50
|
|
50
51
|
MERGED_PARAMS = 'rack-app.params.merged'.freeze
|
51
52
|
VALIDATED_PARAMS = 'rack-app.params.validated'.freeze
|
52
|
-
QUERY_STRING_PARAMS =
|
53
|
+
QUERY_STRING_PARAMS = 'rack-app.params.query_string'.freeze
|
53
54
|
PATH_SEGMENTS_PARAMS = 'rack-app.params.path_segments'.freeze
|
54
55
|
|
55
56
|
PAYLOAD_PARSER = 'rack-app.payload.parser'.freeze
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class Rack::App::Handlers < ::Hash
|
2
|
+
attr_reader :env, :request, :response
|
3
|
+
|
4
|
+
def initialize(env, request, response)
|
5
|
+
@env = env
|
6
|
+
@request = request
|
7
|
+
@response = response
|
8
|
+
end
|
9
|
+
|
10
|
+
def get(klass)
|
11
|
+
self[klass] ||= klass.new.tap do |h|
|
12
|
+
h.env = @env
|
13
|
+
h.request = @request
|
14
|
+
h.response = @response
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class Rack::App::Hook
|
2
|
+
|
3
|
+
attr_accessor :Class, :block
|
4
|
+
|
5
|
+
def initialize(options = {}, &block)
|
6
|
+
self.Class = options[:class] || raise(ArgumentError, "missing :class keyword argument")
|
7
|
+
self.block = block
|
8
|
+
end
|
9
|
+
|
10
|
+
def exec(env)
|
11
|
+
env[Rack::App::Constants::ENV::HANDLERS].get(self.Class).instance_exec(&self.block)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
@@ -1,6 +1,10 @@
|
|
1
1
|
module Rack::App::InstanceMethods::Core
|
2
2
|
|
3
|
-
attr_writer :request, :response
|
3
|
+
attr_writer :env, :request, :response
|
4
|
+
|
5
|
+
def env
|
6
|
+
@env || raise("env object is not set for #{self.class}")
|
7
|
+
end
|
4
8
|
|
5
9
|
def request
|
6
10
|
@request || raise("request object is not set for #{self.class}")
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require "rack/builder"
|
2
2
|
require "rack/request"
|
3
3
|
require "rack/response"
|
4
|
+
|
4
5
|
class Rack::App::Middlewares::Configuration
|
5
6
|
|
6
7
|
def initialize(app, config)
|
@@ -11,10 +12,10 @@ class Rack::App::Middlewares::Configuration
|
|
11
12
|
end
|
12
13
|
|
13
14
|
def call(env)
|
14
|
-
|
15
|
-
env[::Rack::App::Constants::ENV::SERIALIZER]= @serializer
|
16
|
-
env[::Rack::App::Constants::ENV::PAYLOAD_PARSER]= @payload_parser
|
17
|
-
env[::Rack::App::Constants::ENV::PAYLOAD_GETTER]= lambda do
|
15
|
+
setup_handler(env)
|
16
|
+
env[::Rack::App::Constants::ENV::SERIALIZER] = @serializer
|
17
|
+
env[::Rack::App::Constants::ENV::PAYLOAD_PARSER] = @payload_parser
|
18
|
+
env[::Rack::App::Constants::ENV::PAYLOAD_GETTER] = lambda do
|
18
19
|
env[::Rack::App::Constants::ENV::PARSED_PAYLOAD] ||= env[::Rack::App::Constants::ENV::PAYLOAD_PARSER].parse_env(env)
|
19
20
|
end
|
20
21
|
@app.call(env)
|
@@ -22,11 +23,17 @@ class Rack::App::Middlewares::Configuration
|
|
22
23
|
|
23
24
|
protected
|
24
25
|
|
25
|
-
def
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
def setup_handler(env)
|
27
|
+
request = ::Rack::Request.new(env)
|
28
|
+
response = ::Rack::Response.new
|
29
|
+
h = @handler_class.new
|
30
|
+
h.env = env
|
31
|
+
h.request = request
|
32
|
+
h.response = response
|
33
|
+
handlers = ::Rack::App::Handlers.new(env, request, response)
|
34
|
+
handlers[@handler_class] = h
|
35
|
+
env[::Rack::App::Constants::ENV::HANDLERS] = handlers
|
36
|
+
env[::Rack::App::Constants::ENV::HANDLER] = handlers[@handler_class]
|
30
37
|
end
|
31
38
|
|
32
39
|
def extname(env)
|
@@ -1,8 +1,8 @@
|
|
1
1
|
class Rack::App::Middlewares::Hooks::Base
|
2
2
|
|
3
|
-
def initialize(app,
|
3
|
+
def initialize(app, hook)
|
4
4
|
@app = app
|
5
|
-
@
|
5
|
+
@hook = hook
|
6
6
|
end
|
7
7
|
|
8
8
|
def call(env)
|
@@ -13,7 +13,7 @@ class Rack::App::Middlewares::Hooks::Base
|
|
13
13
|
|
14
14
|
def execute_hook(env)
|
15
15
|
catch :rack_response do
|
16
|
-
|
16
|
+
@hook.exec(env)
|
17
17
|
nil
|
18
18
|
end
|
19
19
|
end
|
@@ -2,13 +2,17 @@ module Rack::App::SingletonMethods::Hooks
|
|
2
2
|
|
3
3
|
def before(&block)
|
4
4
|
@before_hooks ||= []
|
5
|
-
|
5
|
+
unless block.nil?
|
6
|
+
@before_hooks << ::Rack::App::Hook.new(class: self, &block)
|
7
|
+
end
|
6
8
|
@before_hooks
|
7
9
|
end
|
8
10
|
|
9
11
|
def after(&block)
|
10
12
|
@after_hooks ||= []
|
11
|
-
|
13
|
+
unless block.nil?
|
14
|
+
@after_hooks << ::Rack::App::Hook.new(class: self, &block)
|
15
|
+
end
|
12
16
|
@after_hooks
|
13
17
|
end
|
14
18
|
|
data/lib/rack/app.rb
CHANGED
@@ -10,11 +10,13 @@ class Rack::App
|
|
10
10
|
require 'rack/app/utils'
|
11
11
|
require 'rack/app/cli'
|
12
12
|
require 'rack/app/test'
|
13
|
+
require 'rack/app/hook'
|
13
14
|
require 'rack/app/block'
|
14
15
|
require 'rack/app/logger'
|
15
16
|
require 'rack/app/params'
|
16
|
-
require 'rack/app/payload'
|
17
17
|
require 'rack/app/router'
|
18
|
+
require 'rack/app/payload'
|
19
|
+
require 'rack/app/handlers'
|
18
20
|
require 'rack/app/endpoint'
|
19
21
|
require 'rack/app/streamer'
|
20
22
|
require 'rack/app/extension'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-app
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 9.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Luzsi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-09-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -120,6 +120,8 @@ files:
|
|
120
120
|
- lib/rack/app/error_handler.rb
|
121
121
|
- lib/rack/app/extension.rb
|
122
122
|
- lib/rack/app/file_server.rb
|
123
|
+
- lib/rack/app/handlers.rb
|
124
|
+
- lib/rack/app/hook.rb
|
123
125
|
- lib/rack/app/instance_methods.rb
|
124
126
|
- lib/rack/app/instance_methods/core.rb
|
125
127
|
- lib/rack/app/instance_methods/http_status.rb
|