rack-app 8.1.0 → 10.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 +13 -12
- 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/request.rb +16 -0
- data/lib/rack/app/singleton_methods/hooks.rb +6 -2
- data/lib/rack/app.rb +4 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b3058bb6d9204572e2c65f667ea438a8122a47463fb4403ce033f05bf026234
|
4
|
+
data.tar.gz: 8948e893f2801919abce11a18b437530263dadb3111daa8a4fa3ec3a58fee66f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0407ce827d7f76bbaa08b240977f985ce7f4eb77adc38ebb44e0e08cda29d2d873db29f351220d867cfa6bfd6d57dd244a1a07103466d01c052076a468c27a0
|
7
|
+
data.tar.gz: 674026a697470157da4809c7270223e1177c662553f5d09a1c6260a979ed3cdec9e9233c8504ac0bdfdcff12b7b6cd7e4afb392e3596f5c45f42fe86bf343341
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
10.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,16 +40,17 @@ 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
|
46
47
|
|
47
|
-
PARAMS_GETTER = 'rack-app.params.getter'
|
48
|
+
PARAMS_GETTER = 'rack-app.params.getter'.freeze
|
48
49
|
PARAMS = 'rack-app.params.object'.freeze
|
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::App::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
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "rack/request"
|
2
|
+
class Rack::App::Request < ::Rack::Request
|
3
|
+
|
4
|
+
def params
|
5
|
+
@env[::Rack::App::Constants::ENV::PARAMS].to_hash
|
6
|
+
end
|
7
|
+
|
8
|
+
def path_segments_params
|
9
|
+
@env[::Rack::App::Constants::ENV::PARAMS].path_segments_params
|
10
|
+
end
|
11
|
+
|
12
|
+
def query_string_params
|
13
|
+
@env[::Rack::App::Constants::ENV::PARAMS].query_string_params
|
14
|
+
end
|
15
|
+
|
16
|
+
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,14 @@ 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/request'
|
19
|
+
require 'rack/app/payload'
|
20
|
+
require 'rack/app/handlers'
|
18
21
|
require 'rack/app/endpoint'
|
19
22
|
require 'rack/app/streamer'
|
20
23
|
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: 10.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-11 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
|
@@ -153,6 +155,7 @@ files:
|
|
153
155
|
- lib/rack/app/payload/parser.rb
|
154
156
|
- lib/rack/app/payload/parser/builder.rb
|
155
157
|
- lib/rack/app/payload/parser/builder/formats.rb
|
158
|
+
- lib/rack/app/request.rb
|
156
159
|
- lib/rack/app/request_configurator.rb
|
157
160
|
- lib/rack/app/request_stream.rb
|
158
161
|
- lib/rack/app/router.rb
|