rack-app 5.11.1 → 5.12.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 +4 -4
- data/VERSION +1 -1
- data/lib/rack/app/constants.rb +1 -0
- data/lib/rack/app/endpoint.rb +6 -0
- data/lib/rack/app/instance_methods.rb +2 -0
- data/lib/rack/app/instance_methods/path_to.rb +27 -0
- data/lib/rack/app/router.rb +15 -0
- metadata +3 -3
- data/lib/rack/app/router/base.rb +0 -75
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad41bbced4baeeea08b32f690ed2268453b9491b
|
4
|
+
data.tar.gz: 5b02692483edeeffb9aaf5e8f5d15ba763f426e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 522f2d363ead4984e3afb39c81f801e8aec3f73cdfb6f897729756af7635a8ae40d0290f5257b99124f7bf3d9de9b3f14f1741d5868762d3dd5cdc0d2ff63619
|
7
|
+
data.tar.gz: 714c400a866ed8f47c386ea7dafdee6562ab97f590338b8f45d3bdd5b5fec04981afbd47dd8c9df951a6d33c0c3c9bbb48101432caef42de202859b1734cda63
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
5.
|
1
|
+
5.12.0
|
data/lib/rack/app/constants.rb
CHANGED
@@ -38,6 +38,7 @@ module Rack::App::Constants
|
|
38
38
|
REQUEST_PATH = Rack::App::Constants.rack_constant(:REQUEST_PATH, "REQUEST_PATH")
|
39
39
|
REQUEST_METHOD = Rack::App::Constants.rack_constant(:REQUEST_METHOD, "REQUEST_METHOD")
|
40
40
|
|
41
|
+
ROUTER = 'rack-app.router'.freeze
|
41
42
|
EXTNAME = 'rack-app.extname'.freeze
|
42
43
|
SERIALIZER = 'rack-app.serializer'.freeze
|
43
44
|
CONTENT_TYPE = 'CONTENT_TYPE'.freeze
|
data/lib/rack/app/endpoint.rb
CHANGED
@@ -3,6 +3,7 @@ module Rack::App::InstanceMethods
|
|
3
3
|
require 'rack/app/instance_methods/core'
|
4
4
|
require 'rack/app/instance_methods/http_status'
|
5
5
|
require 'rack/app/instance_methods/redirect_to'
|
6
|
+
require 'rack/app/instance_methods/path_to'
|
6
7
|
require 'rack/app/instance_methods/payload'
|
7
8
|
require 'rack/app/instance_methods/serve_file'
|
8
9
|
require 'rack/app/instance_methods/streaming'
|
@@ -10,6 +11,7 @@ module Rack::App::InstanceMethods
|
|
10
11
|
include Rack::App::InstanceMethods::Core
|
11
12
|
include Rack::App::InstanceMethods::HTTPStatus
|
12
13
|
include Rack::App::InstanceMethods::RedirectTo
|
14
|
+
include Rack::App::InstanceMethods::PathTo
|
13
15
|
include Rack::App::InstanceMethods::Payload
|
14
16
|
include Rack::App::InstanceMethods::ServeFile
|
15
17
|
include Rack::App::InstanceMethods::Streaming
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Rack::App::InstanceMethods::PathTo
|
3
|
+
def path_to(defined_path, options = {})
|
4
|
+
app_class = options[:class] || self.class
|
5
|
+
|
6
|
+
query_string_hash = options[:params] || {}
|
7
|
+
options.each do |k, v|
|
8
|
+
k.is_a?(String) && query_string_hash[k] = v
|
9
|
+
end
|
10
|
+
|
11
|
+
router = request.env[Rack::App::Constants::ENV::ROUTER]
|
12
|
+
final_path = router.final_path_for(app_class, defined_path)
|
13
|
+
|
14
|
+
path_keys = final_path.scan(/:(\w+)/).flatten
|
15
|
+
|
16
|
+
path_keys.each do |key|
|
17
|
+
value = query_string_hash.delete(key) || params[key] || raise("missing path-key value for #{key}!")
|
18
|
+
final_path.gsub!(/:#{key}/, value.to_s)
|
19
|
+
end
|
20
|
+
|
21
|
+
unless query_string_hash.empty?
|
22
|
+
final_path.concat("?" + Rack::App::Utils.encode_www_form(query_string_hash))
|
23
|
+
end
|
24
|
+
|
25
|
+
final_path
|
26
|
+
end
|
27
|
+
end
|
data/lib/rack/app/router.rb
CHANGED
@@ -12,6 +12,7 @@ class Rack::App::Router
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def call(env)
|
15
|
+
env[Rack::App::Constants::ENV::ROUTER]= self
|
15
16
|
@tree.call(env) || NOT_FOUND_APP.call(env)
|
16
17
|
end
|
17
18
|
|
@@ -27,6 +28,7 @@ class Rack::App::Router
|
|
27
28
|
|
28
29
|
# add ! to method name
|
29
30
|
def reset
|
31
|
+
@lookup_paths = Hash.new #(Hash.new)
|
30
32
|
@tree = Rack::App::Router::Tree.new
|
31
33
|
compile_registered_endpoints!
|
32
34
|
end
|
@@ -61,6 +63,10 @@ class Rack::App::Router
|
|
61
63
|
|
62
64
|
end
|
63
65
|
|
66
|
+
def final_path_for(klass, defined_path)
|
67
|
+
(@lookup_paths[klass][defined_path] || raise("missing path reference: #{klass}/#{original_path}")).dup
|
68
|
+
end
|
69
|
+
|
64
70
|
protected
|
65
71
|
|
66
72
|
def initialize
|
@@ -75,6 +81,15 @@ class Rack::App::Router
|
|
75
81
|
|
76
82
|
def compile_endpoint!(endpoint)
|
77
83
|
@tree.add(endpoint)
|
84
|
+
add_to_lookup_paths(endpoint)
|
85
|
+
end
|
86
|
+
|
87
|
+
def add_to_lookup_paths(endpoint)
|
88
|
+
return unless endpoint.rack_app?
|
89
|
+
def_path = endpoint.config.defined_request_path
|
90
|
+
final_path = endpoint.request_path
|
91
|
+
dictionary = @lookup_paths[endpoint.config.app_class] ||= {}
|
92
|
+
dictionary[def_path]= final_path
|
78
93
|
end
|
79
94
|
|
80
95
|
end
|
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: 5.
|
4
|
+
version: 5.12.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: 2017-02-
|
11
|
+
date: 2017-02-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -117,6 +117,7 @@ files:
|
|
117
117
|
- lib/rack/app/instance_methods.rb
|
118
118
|
- lib/rack/app/instance_methods/core.rb
|
119
119
|
- lib/rack/app/instance_methods/http_status.rb
|
120
|
+
- lib/rack/app/instance_methods/path_to.rb
|
120
121
|
- lib/rack/app/instance_methods/payload.rb
|
121
122
|
- lib/rack/app/instance_methods/redirect_to.rb
|
122
123
|
- lib/rack/app/instance_methods/serve_file.rb
|
@@ -148,7 +149,6 @@ files:
|
|
148
149
|
- lib/rack/app/request_configurator.rb
|
149
150
|
- lib/rack/app/request_stream.rb
|
150
151
|
- lib/rack/app/router.rb
|
151
|
-
- lib/rack/app/router/base.rb
|
152
152
|
- lib/rack/app/router/tree.rb
|
153
153
|
- lib/rack/app/router/tree/branch.rb
|
154
154
|
- lib/rack/app/router/tree/env.rb
|
data/lib/rack/app/router/base.rb
DELETED
@@ -1,75 +0,0 @@
|
|
1
|
-
class Rack::App::Router::Base
|
2
|
-
|
3
|
-
def call(env)
|
4
|
-
app = get_app(env)
|
5
|
-
app && app.call(env)
|
6
|
-
end
|
7
|
-
|
8
|
-
def endpoints
|
9
|
-
@endpoints ||= []
|
10
|
-
end
|
11
|
-
|
12
|
-
def register_endpoint!(endpoint)
|
13
|
-
endpoints.push(endpoint)
|
14
|
-
compile_endpoint!(endpoint)
|
15
|
-
return endpoint
|
16
|
-
end
|
17
|
-
|
18
|
-
def reset
|
19
|
-
clean_routes!
|
20
|
-
compile_registered_endpoints!
|
21
|
-
end
|
22
|
-
|
23
|
-
protected
|
24
|
-
|
25
|
-
def get_app(env)
|
26
|
-
raise(NotImplementedError)
|
27
|
-
end
|
28
|
-
|
29
|
-
def compile_endpoint!(endpoint)
|
30
|
-
raise(NotImplementedError)
|
31
|
-
end
|
32
|
-
|
33
|
-
def clean_routes!
|
34
|
-
raise(NotImplementedError)
|
35
|
-
end
|
36
|
-
|
37
|
-
def compile_registered_endpoints!
|
38
|
-
raise(NotImplementedError)
|
39
|
-
end
|
40
|
-
|
41
|
-
def fetch_context(request_method, request_path)
|
42
|
-
raise(NotImplementedError)
|
43
|
-
end
|
44
|
-
|
45
|
-
def as_app(endpoint_or_app)
|
46
|
-
if endpoint_or_app.respond_to?(:to_app)
|
47
|
-
endpoint_or_app.to_app
|
48
|
-
else
|
49
|
-
endpoint_or_app
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def find_by_path_infos(env)
|
54
|
-
yield(raw_path_info(env)) || yield(formatted_path_info(env))
|
55
|
-
end
|
56
|
-
|
57
|
-
def get_request_method(env)
|
58
|
-
env[::Rack::App::Constants::ENV::REQUEST_METHOD]
|
59
|
-
end
|
60
|
-
|
61
|
-
def raw_path_info(env)
|
62
|
-
env[::Rack::App::Constants::ENV::PATH_INFO]
|
63
|
-
end
|
64
|
-
|
65
|
-
def formatted_path_info(env)
|
66
|
-
path_info = raw_path_info(env).dup
|
67
|
-
path_info.slice!(/#{Regexp.escape(extname(env))}$/)
|
68
|
-
path_info
|
69
|
-
end
|
70
|
-
|
71
|
-
def extname(env)
|
72
|
-
env[::Rack::App::Constants::ENV::EXTNAME]
|
73
|
-
end
|
74
|
-
|
75
|
-
end
|