rack-app 2.3.1 → 3.0.0.alpha
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +5 -9
- data/VERSION +1 -1
- data/lib/rack/app.rb +2 -0
- data/lib/rack/app/constants.rb +2 -1
- data/lib/rack/app/endpoint.rb +4 -4
- data/lib/rack/app/extension.rb +29 -0
- data/lib/rack/app/params.rb +18 -8
- data/lib/rack/app/request_configurator.rb +1 -1
- data/lib/rack/app/singleton_methods.rb +2 -2
- data/lib/rack/app/singleton_methods/http_methods.rb +2 -0
- data/lib/rack/app/singleton_methods/inheritance.rb +15 -13
- data/lib/rack/app/singleton_methods/mounting.rb +20 -15
- data/lib/rack/app/singleton_methods/rack_interface.rb +4 -2
- data/lib/rack/app/singleton_methods/route_handling.rb +6 -4
- data/lib/rack/app/singleton_methods/{utility.rb → settings.rb} +23 -7
- data/lib/rack/app/test.rb +10 -40
- data/lib/rack/app/test/singleton_methods.rb +15 -0
- data/lib/rack/app/test/utils.rb +34 -35
- data/lib/rack/app/utils.rb +7 -0
- data/lib/rack/app/utils/deep_dup.rb +90 -0
- metadata +8 -7
- data/bin/console +0 -14
- data/bin/setup +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ebb99d6cbc443f59e0f17c2d1216ed44ae7d8b5f
|
4
|
+
data.tar.gz: cb9d4c1a858802c241c76fcc4ba48c113b06b5e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6398d60c1909301924d191e4875e81c945c8ec06cd41b3e2158a87744bd2080e1c0a3c9074a7ff6f3cdb3f7e217eefa60976a432259cb7bdfd6f48cb96d1dcae
|
7
|
+
data.tar.gz: bb3c51ab85a38d507f685ebe3c7d61f1936f354c0cce2d1009072fa45ca1ee488f583805f75ede3c5c3b22957abeed9a6d6adc42cb73a79ab23185608e51508e
|
data/.travis.yml
CHANGED
@@ -6,10 +6,13 @@ install:
|
|
6
6
|
- bundle install
|
7
7
|
|
8
8
|
rvm:
|
9
|
+
|
9
10
|
- 1.8
|
10
11
|
- 1.9
|
11
|
-
- 2.0
|
12
|
-
- 2.1
|
12
|
+
- 2.0.0
|
13
|
+
- 2.1.1
|
14
|
+
- 2.1.2
|
15
|
+
|
13
16
|
- jruby-18mode
|
14
17
|
- jruby-19mode
|
15
18
|
- ree
|
@@ -18,13 +21,6 @@ rvm:
|
|
18
21
|
- jruby-head
|
19
22
|
|
20
23
|
matrix:
|
21
|
-
include:
|
22
|
-
|
23
|
-
- rvm: ruby-head
|
24
|
-
before_install:
|
25
|
-
- 'gem update --system 2.4.8'
|
26
|
-
|
27
|
-
|
28
24
|
allow_failures:
|
29
25
|
- rvm: ruby-head
|
30
26
|
- rvm: jruby-head
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
3.0.0.alpha
|
data/lib/rack/app.rb
CHANGED
@@ -7,10 +7,12 @@ class Rack::App
|
|
7
7
|
require 'rack/app/version'
|
8
8
|
require 'rack/app/constants'
|
9
9
|
|
10
|
+
require 'rack/app/test'
|
10
11
|
require 'rack/app/utils'
|
11
12
|
require 'rack/app/params'
|
12
13
|
require 'rack/app/router'
|
13
14
|
require 'rack/app/endpoint'
|
15
|
+
require 'rack/app/extension'
|
14
16
|
require 'rack/app/serializer'
|
15
17
|
require 'rack/app/file_server'
|
16
18
|
require 'rack/app/error_handler'
|
data/lib/rack/app/constants.rb
CHANGED
data/lib/rack/app/endpoint.rb
CHANGED
@@ -7,7 +7,7 @@ class Rack::App::Endpoint
|
|
7
7
|
def initialize(properties)
|
8
8
|
@properties = properties
|
9
9
|
|
10
|
-
@
|
10
|
+
@app_class = properties[:app_class]
|
11
11
|
@error_handler = properties[:error_handler] || Rack::App::ErrorHandler.new
|
12
12
|
@serializer = properties[:serializer] || Rack::App::Serializer.new
|
13
13
|
@headers = properties[:default_headers] || {}
|
@@ -37,11 +37,11 @@ class Rack::App::Endpoint
|
|
37
37
|
|
38
38
|
def get_response_body(rack_request, rack_response)
|
39
39
|
|
40
|
-
request_handler = @
|
40
|
+
request_handler = @app_class.new
|
41
41
|
set_default_headers(rack_response)
|
42
42
|
request_handler.request = rack_request
|
43
43
|
request_handler.response = rack_response
|
44
|
-
rack_request.env[
|
44
|
+
rack_request.env[::Rack::App::Constants::PATH_PARAMS_MATCHER]= @path_params_matcher.dup
|
45
45
|
return @error_handler.execute_with_error_handling_for(request_handler, @endpoint_method_name)
|
46
46
|
|
47
47
|
end
|
@@ -67,7 +67,7 @@ class Rack::App::Endpoint
|
|
67
67
|
|
68
68
|
def register_method_to_app_class(proc)
|
69
69
|
method_name = ::Rack::App::Utils.uuid
|
70
|
-
@
|
70
|
+
@app_class.__send__(:define_method, method_name, &proc)
|
71
71
|
return method_name
|
72
72
|
end
|
73
73
|
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class Rack::App::Extension
|
2
|
+
class << self
|
3
|
+
|
4
|
+
def includes
|
5
|
+
@includes ||= []
|
6
|
+
end
|
7
|
+
|
8
|
+
def extends
|
9
|
+
@extends ||= []
|
10
|
+
end
|
11
|
+
|
12
|
+
def inheritances
|
13
|
+
@on_inheritances ||= []
|
14
|
+
end
|
15
|
+
|
16
|
+
def include(endpoint_methods_module)
|
17
|
+
includes << endpoint_methods_module
|
18
|
+
end
|
19
|
+
|
20
|
+
def extend(app_class_methods_module)
|
21
|
+
extends << app_class_methods_module
|
22
|
+
end
|
23
|
+
|
24
|
+
def on_inheritance(&block)
|
25
|
+
inheritances << block
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
data/lib/rack/app/params.rb
CHANGED
@@ -1,24 +1,26 @@
|
|
1
1
|
require 'cgi'
|
2
2
|
class Rack::App::Params
|
3
3
|
|
4
|
-
def initialize(request_env)
|
5
|
-
@request_env = request_env
|
6
|
-
end
|
7
|
-
|
8
4
|
def to_hash
|
9
5
|
query_params.merge(request_path_params)
|
10
6
|
end
|
11
7
|
|
12
8
|
protected
|
13
9
|
|
10
|
+
def initialize(request_env)
|
11
|
+
@request_env = request_env
|
12
|
+
end
|
13
|
+
|
14
14
|
def query_params
|
15
|
-
|
15
|
+
raw_cgi_params.reduce({}) do |params_collection, (k, v)|
|
16
16
|
|
17
|
-
if
|
17
|
+
if single_paramter_value?(v)
|
18
18
|
params_collection[k]= v[0]
|
19
|
+
|
19
20
|
else
|
20
21
|
k = k.sub(/\[\]$/, '')
|
21
22
|
params_collection[k]= v
|
23
|
+
|
22
24
|
end
|
23
25
|
|
24
26
|
params_collection
|
@@ -26,6 +28,14 @@ class Rack::App::Params
|
|
26
28
|
end
|
27
29
|
end
|
28
30
|
|
31
|
+
def single_paramter_value?(v)
|
32
|
+
v.is_a?(Array) and v.length === 1
|
33
|
+
end
|
34
|
+
|
35
|
+
def raw_cgi_params
|
36
|
+
CGI.parse(@request_env[::Rack::QUERY_STRING].to_s)
|
37
|
+
end
|
38
|
+
|
29
39
|
def request_path_params
|
30
40
|
path_params = {}
|
31
41
|
path_params.merge!(extract_path_params) unless path_params_matcher.empty?
|
@@ -40,11 +50,11 @@ class Rack::App::Params
|
|
40
50
|
end
|
41
51
|
|
42
52
|
def request_path_parts
|
43
|
-
Rack::App::
|
53
|
+
@request_env[::Rack::App::Constants::NORMALIZED_PATH_INFO].split('/')
|
44
54
|
end
|
45
55
|
|
46
56
|
def path_params_matcher
|
47
|
-
@request_env[
|
57
|
+
@request_env[::Rack::App::Constants::PATH_PARAMS_MATCHER] || {}
|
48
58
|
end
|
49
59
|
|
50
60
|
end
|
@@ -3,7 +3,7 @@ module Rack::App::RequestConfigurator
|
|
3
3
|
extend self
|
4
4
|
|
5
5
|
def configure(request_env)
|
6
|
-
request_env[Rack::App::Constants::
|
6
|
+
request_env[Rack::App::Constants::NORMALIZED_PATH_INFO]= Rack::App::Utils.normalize_path(request_env[::Rack::PATH_INFO])
|
7
7
|
request_env
|
8
8
|
end
|
9
9
|
|
@@ -5,13 +5,13 @@ module Rack::App::SingletonMethods
|
|
5
5
|
require 'rack/app/singleton_methods/mounting'
|
6
6
|
require 'rack/app/singleton_methods/rack_interface'
|
7
7
|
require 'rack/app/singleton_methods/route_handling'
|
8
|
-
require 'rack/app/singleton_methods/
|
8
|
+
require 'rack/app/singleton_methods/settings'
|
9
9
|
|
10
10
|
include Rack::App::SingletonMethods::HttpMethods
|
11
11
|
include Rack::App::SingletonMethods::Inheritance
|
12
12
|
include Rack::App::SingletonMethods::Mounting
|
13
13
|
include Rack::App::SingletonMethods::RackInterface
|
14
14
|
include Rack::App::SingletonMethods::RouteHandling
|
15
|
-
include Rack::App::SingletonMethods::
|
15
|
+
include Rack::App::SingletonMethods::Settings
|
16
16
|
|
17
17
|
end
|
@@ -1,26 +1,28 @@
|
|
1
1
|
module Rack::App::SingletonMethods::Inheritance
|
2
2
|
|
3
|
-
def
|
3
|
+
def on_inheritance(&block)
|
4
|
+
@on_inheritance ||= []
|
5
|
+
@on_inheritance << block unless block.nil?
|
6
|
+
@on_inheritance
|
7
|
+
end
|
8
|
+
|
9
|
+
protected
|
10
|
+
|
11
|
+
def inherited(child)
|
4
12
|
|
5
|
-
|
6
|
-
|
7
|
-
|
13
|
+
child.serializer(&serializer.logic)
|
14
|
+
child.headers.merge!(headers)
|
15
|
+
child.__send__(:middlewares).push(*middlewares)
|
8
16
|
|
9
17
|
on_inheritance.each do |block|
|
10
|
-
block.call(self,
|
11
|
-
|
18
|
+
block.call(self, child)
|
19
|
+
child.on_inheritance(&block)
|
12
20
|
end
|
13
21
|
|
14
22
|
error.handlers.each do |ex_class, block|
|
15
|
-
|
23
|
+
child.error(ex_class, &block)
|
16
24
|
end
|
17
25
|
|
18
26
|
end
|
19
27
|
|
20
|
-
def on_inheritance(&block)
|
21
|
-
@on_inheritance ||= []
|
22
|
-
@on_inheritance << block unless block.nil?
|
23
|
-
@on_inheritance
|
24
|
-
end
|
25
|
-
|
26
28
|
end
|
@@ -1,40 +1,35 @@
|
|
1
1
|
module Rack::App::SingletonMethods::Mounting
|
2
2
|
|
3
|
-
def on_mounted(&block)
|
4
|
-
@on_mounted ||= []
|
5
|
-
@on_mounted << block unless block.nil?
|
6
|
-
@on_mounted
|
7
|
-
end
|
8
|
-
|
9
|
-
alias while_being_mounted on_mounted
|
10
|
-
|
11
3
|
def mount(api_class, mount_prop={})
|
4
|
+
mount_to_path = ::Rack::App::Utils.deep_dup(mount_prop[:to])
|
12
5
|
|
13
6
|
unless api_class.is_a?(Class) and api_class <= Rack::App
|
14
7
|
raise(ArgumentError, 'Invalid class given for mount, must be a Rack::App')
|
15
8
|
end
|
16
9
|
|
17
|
-
|
18
|
-
|
10
|
+
duplication = ::Rack::App::Utils.deep_dup(api_class)
|
11
|
+
|
12
|
+
duplication.on_mounted.each do |on_mount|
|
13
|
+
duplication.instance_exec(mount_prop, &on_mount)
|
19
14
|
end
|
20
15
|
|
21
|
-
merge_prop = {:namespaces => [@namespaces,
|
22
|
-
router.merge_router!(
|
16
|
+
merge_prop = {:namespaces => [@namespaces, mount_to_path].flatten}
|
17
|
+
router.merge_router!(duplication.router, merge_prop)
|
23
18
|
|
24
19
|
return nil
|
25
20
|
end
|
26
21
|
|
27
22
|
def mount_directory(directory_path, options={})
|
28
23
|
|
29
|
-
directory_full_path = Rack::App::Utils.expand_path(directory_path)
|
24
|
+
directory_full_path = ::Rack::App::Utils.expand_path(directory_path)
|
30
25
|
|
31
26
|
namespace options[:to] do
|
32
27
|
|
33
28
|
Dir.glob(File.join(directory_full_path, '**', '*')).each do |file_path|
|
34
29
|
|
35
30
|
request_path = file_path.sub(/^#{Regexp.escape(directory_full_path)}/, '')
|
36
|
-
get(request_path){ serve_file(file_path) }
|
37
|
-
options(request_path){ '' }
|
31
|
+
get(request_path) { serve_file(file_path) }
|
32
|
+
options(request_path) { '' }
|
38
33
|
|
39
34
|
end
|
40
35
|
|
@@ -52,4 +47,14 @@ module Rack::App::SingletonMethods::Mounting
|
|
52
47
|
@last_description = nil
|
53
48
|
end
|
54
49
|
|
50
|
+
protected
|
51
|
+
|
52
|
+
def on_mounted(&block)
|
53
|
+
@on_mounted ||= []
|
54
|
+
@on_mounted << block unless block.nil?
|
55
|
+
@on_mounted
|
56
|
+
end
|
57
|
+
|
58
|
+
alias while_being_mounted on_mounted
|
59
|
+
|
55
60
|
end
|
@@ -1,10 +1,12 @@
|
|
1
1
|
module Rack::App::SingletonMethods::RackInterface
|
2
2
|
|
3
|
+
public
|
4
|
+
|
3
5
|
def call(request_env)
|
4
6
|
Rack::App::RequestConfigurator.configure(request_env)
|
5
7
|
endpoint = router.fetch_endpoint(
|
6
|
-
request_env[
|
7
|
-
request_env[Rack::App::Constants::
|
8
|
+
request_env[::Rack::REQUEST_METHOD],
|
9
|
+
request_env[Rack::App::Constants::NORMALIZED_PATH_INFO])
|
8
10
|
endpoint.call(request_env)
|
9
11
|
end
|
10
12
|
|
@@ -1,5 +1,11 @@
|
|
1
1
|
module Rack::App::SingletonMethods::RouteHandling
|
2
2
|
|
3
|
+
def router
|
4
|
+
@router ||= Rack::App::Router.new
|
5
|
+
end
|
6
|
+
|
7
|
+
protected
|
8
|
+
|
3
9
|
def root(endpoint_path)
|
4
10
|
%W[GET POST PUT DELETE OPTIONS PATCH HEAD].each do |request_method|
|
5
11
|
endpoint = router.fetch_endpoint(request_method, endpoint_path)
|
@@ -54,8 +60,4 @@ module Rack::App::SingletonMethods::RouteHandling
|
|
54
60
|
nil
|
55
61
|
end
|
56
62
|
|
57
|
-
def router
|
58
|
-
@router ||= Rack::App::Router.new
|
59
|
-
end
|
60
|
-
|
61
63
|
end
|
@@ -1,4 +1,6 @@
|
|
1
|
-
module Rack::App::SingletonMethods::
|
1
|
+
module Rack::App::SingletonMethods::Settings
|
2
|
+
|
3
|
+
protected
|
2
4
|
|
3
5
|
def serializer(&definition_how_to_serialize)
|
4
6
|
@serializer ||= Rack::App::Serializer.new
|
@@ -16,13 +18,17 @@ module Rack::App::SingletonMethods::Utility
|
|
16
18
|
@headers
|
17
19
|
end
|
18
20
|
|
19
|
-
def
|
20
|
-
|
21
|
-
|
22
|
-
@middlewares
|
23
|
-
end
|
21
|
+
def extensions(*extensions)
|
22
|
+
extensions.each do |ext|
|
23
|
+
if ext.is_a?(::Class) && ext < (::Rack::App::Extension)
|
24
24
|
|
25
|
-
|
25
|
+
ext.includes.each { |m| include(m) }
|
26
|
+
ext.extends.each { |m| extend(m) }
|
27
|
+
ext.inheritances.each { |block| on_inheritance(&block) }
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
26
32
|
|
27
33
|
def error(*exception_classes, &block)
|
28
34
|
@error_handler ||= Rack::App::ErrorHandler.new
|
@@ -33,4 +39,14 @@ module Rack::App::SingletonMethods::Utility
|
|
33
39
|
return @error_handler
|
34
40
|
end
|
35
41
|
|
42
|
+
private
|
43
|
+
|
44
|
+
def middlewares(&block)
|
45
|
+
@middlewares ||= []
|
46
|
+
@middlewares << block unless block.nil?
|
47
|
+
@middlewares
|
48
|
+
end
|
49
|
+
|
50
|
+
alias middleware middlewares
|
51
|
+
|
36
52
|
end
|
data/lib/rack/app/test.rb
CHANGED
@@ -3,54 +3,24 @@ require 'rack/app'
|
|
3
3
|
module Rack::App::Test
|
4
4
|
|
5
5
|
require 'rack/app/test/utils'
|
6
|
+
require 'rack/app/test/singleton_methods'
|
6
7
|
|
7
8
|
def self.included(klass)
|
8
|
-
klass.__send__(:extend,
|
9
|
+
klass.__send__(:extend, self::SingletonMethods)
|
9
10
|
end
|
10
11
|
|
11
|
-
|
12
|
+
attr_reader :last_response
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
begin
|
16
|
-
let(:rack_app){ rack_app_by(*args,&constructor) }
|
17
|
-
rescue NoMethodError
|
18
|
-
define_method(:rack_app) do
|
19
|
-
rack_app_by(*args,&constructor)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
14
|
+
[:get, :post, :put, :delete, :options, :patch].each do |request_method|
|
15
|
+
define_method(request_method) do |*args|
|
26
16
|
|
27
|
-
|
28
|
-
|
29
|
-
|
17
|
+
properties = args.select { |e| e.is_a?(Hash) }.reduce({}, &:merge!)
|
18
|
+
url = args.select { |e| e.is_a?(String) }.first || properties.delete(:url)
|
19
|
+
request = Rack::MockRequest.new(rack_app)
|
20
|
+
env = Rack::App::Test::Utils.env_by(properties)
|
30
21
|
|
31
|
-
|
32
|
-
subject_app = rack_app_class
|
33
|
-
else
|
34
|
-
subject_app = Class.new(rack_app_class || Rack::App)
|
35
|
-
subject_app.class_eval(&constructor)
|
36
|
-
end
|
22
|
+
return @last_response = request.__send__(request_method, url, env)
|
37
23
|
|
38
|
-
subject_app
|
39
|
-
end
|
40
|
-
|
41
|
-
[:get, :post, :put, :delete, :options, :patch].each do |request_method|
|
42
|
-
define_method(request_method) do |properties|
|
43
|
-
properties ||= Hash.new
|
44
|
-
url = properties.delete(:url)
|
45
|
-
request_env = Rack::App::Test::Utils.request_env_by(request_method, url, properties)
|
46
|
-
raw_response = rack_app.call(request_env)
|
47
|
-
|
48
|
-
body = []
|
49
|
-
raw_response[2].each do |e|
|
50
|
-
body << e
|
51
|
-
end
|
52
|
-
|
53
|
-
return Rack::Response.new(body,raw_response[0],raw_response[1])
|
54
24
|
end
|
55
25
|
end
|
56
26
|
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Rack::App::Test::SingletonMethods
|
2
|
+
|
3
|
+
def rack_app(*args, &constructor)
|
4
|
+
|
5
|
+
begin
|
6
|
+
let(:rack_app) { Rack::App::Test::Utils.rack_app_by(*args, &constructor) }
|
7
|
+
rescue NoMethodError
|
8
|
+
define_method(:rack_app) do
|
9
|
+
rack_app_by(*args, &constructor)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
data/lib/rack/app/test/utils.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
module Rack::App::Test::Utils
|
2
|
+
|
2
3
|
extend self
|
3
4
|
|
4
5
|
def format_properties(properties)
|
@@ -9,48 +10,47 @@ module Rack::App::Test::Utils
|
|
9
10
|
properties
|
10
11
|
end
|
11
12
|
|
12
|
-
def
|
13
|
+
def rack_app_by(*args, &constructor)
|
14
|
+
subject_app = nil
|
13
15
|
|
14
|
-
|
15
|
-
additional_headers = properties[:headers].reduce({}) { |m, (k, v)| m.merge("HTTP_#{k.to_s.gsub('-', '_').upcase}" => v.to_s) }
|
16
|
+
rack_app_class = args.shift
|
16
17
|
|
17
|
-
|
18
|
+
if constructor.nil?
|
19
|
+
subject_app = rack_app_class
|
20
|
+
else
|
21
|
+
subject_app = Class.new(rack_app_class || ::Rack::App)
|
22
|
+
subject_app.class_eval(&constructor)
|
23
|
+
end
|
18
24
|
|
19
|
-
|
25
|
+
subject_app
|
26
|
+
end
|
20
27
|
|
21
|
-
|
22
|
-
payload
|
28
|
+
def env_by(properties)
|
23
29
|
|
24
|
-
|
25
|
-
|
30
|
+
properties = format_properties(properties)
|
31
|
+
env = properties[:headers].reduce({}) { |m, (k, v)| m.merge("HTTP_#{k.to_s.gsub('-', '_').upcase}" => v.to_s) }
|
32
|
+
payload = properties.delete(:payload)
|
33
|
+
env["rack.input"]= ::Rack::Lint::InputWrapper.new(string_io_for(payload))
|
34
|
+
env[::Rack::QUERY_STRING]= encode_www_form(properties[:params].to_a)
|
35
|
+
env.merge!(properties[:env] || {})
|
26
36
|
|
27
|
-
else
|
28
|
-
StringIO.new('')
|
29
37
|
|
30
|
-
|
38
|
+
env
|
39
|
+
end
|
40
|
+
|
41
|
+
def string_io_for(payload)
|
42
|
+
case payload
|
31
43
|
|
32
|
-
|
44
|
+
when IO
|
45
|
+
payload
|
33
46
|
|
34
|
-
|
35
|
-
|
36
|
-
"REQUEST_METHOD" => request_method.to_s.upcase,
|
37
|
-
"REQUEST_PATH" => url,
|
38
|
-
"REQUEST_URI" => url,
|
39
|
-
"PATH_INFO" => url,
|
40
|
-
"SERVER_PROTOCOL" => "HTTP/1.1",
|
41
|
-
"CONTENT_LENGTH" => "0",
|
42
|
-
"CONTENT_TYPE" => "application/x-www-form-urlencoded",
|
43
|
-
"SERVER_NAME" => "hds-dev.ett.local",
|
44
|
-
"SERVER_PORT" => "80",
|
45
|
-
"QUERY_STRING" => encode_www_form(properties[:params].to_a),
|
46
|
-
"HTTP_VERSION" => "HTTP/1.1",
|
47
|
-
"HTTP_USER_AGENT" => "spec",
|
48
|
-
"HTTP_HOST" => "spec.local",
|
49
|
-
"HTTP_ACCEPT_ENCODING" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
|
50
|
-
"HTTP_ACCEPT" => "*/*",
|
51
|
-
"HTTP_CONNECTION" => "close"
|
52
|
-
}.merge(additional_headers)
|
47
|
+
when String
|
48
|
+
StringIO.new(payload.to_s)
|
53
49
|
|
50
|
+
else
|
51
|
+
StringIO.new('')
|
52
|
+
|
53
|
+
end
|
54
54
|
end
|
55
55
|
|
56
56
|
def encode_www_form(enum)
|
@@ -93,9 +93,8 @@ module Rack::App::Test::Utils
|
|
93
93
|
|
94
94
|
def encode_www_form_component(str)
|
95
95
|
str = str.to_s.dup
|
96
|
-
|
97
|
-
|
98
|
-
str.gsub!(from,to)
|
96
|
+
TBLENCWWWCOMP_.each do |from, to|
|
97
|
+
str.gsub!(from, to)
|
99
98
|
end
|
100
99
|
str
|
101
100
|
end
|
data/lib/rack/app/utils.rb
CHANGED
@@ -2,6 +2,8 @@ require 'securerandom'
|
|
2
2
|
module Rack::App::Utils
|
3
3
|
extend self
|
4
4
|
|
5
|
+
require 'rack/app/utils/deep_dup'
|
6
|
+
|
5
7
|
# Normalizes URI path.
|
6
8
|
#
|
7
9
|
# Strips off trailing slash and ensures there is a leading slash.
|
@@ -75,4 +77,9 @@ module Rack::App::Utils
|
|
75
77
|
File.join(directory,basename)
|
76
78
|
end
|
77
79
|
|
80
|
+
|
81
|
+
def deep_dup(object)
|
82
|
+
::Rack::App::Utils::DeepDup.new(object).to_dup
|
83
|
+
end
|
84
|
+
|
78
85
|
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
class Rack::App::Utils::DeepDup
|
2
|
+
|
3
|
+
def initialize(object)
|
4
|
+
@object = object
|
5
|
+
end
|
6
|
+
|
7
|
+
def to_dup
|
8
|
+
@register = {}
|
9
|
+
|
10
|
+
dup(@object)
|
11
|
+
end
|
12
|
+
|
13
|
+
protected
|
14
|
+
|
15
|
+
def registration(object, duplicate)
|
16
|
+
@register[object.object_id]= duplicate
|
17
|
+
duplicate
|
18
|
+
end
|
19
|
+
|
20
|
+
def registered(object)
|
21
|
+
@register[object.object_id]
|
22
|
+
end
|
23
|
+
|
24
|
+
def dup(object)
|
25
|
+
|
26
|
+
return registered(object) if registered(object)
|
27
|
+
|
28
|
+
case object
|
29
|
+
|
30
|
+
when Array
|
31
|
+
dup_array(object)
|
32
|
+
|
33
|
+
when Hash
|
34
|
+
dup_hash(object)
|
35
|
+
|
36
|
+
when Range
|
37
|
+
dup_range(object)
|
38
|
+
|
39
|
+
when Struct
|
40
|
+
dup_struct(object)
|
41
|
+
|
42
|
+
when NilClass, Symbol, Numeric, TrueClass, FalseClass
|
43
|
+
registration(object, object)
|
44
|
+
|
45
|
+
else
|
46
|
+
dup_object(object)
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def dup_array(object)
|
52
|
+
duplication = dup_object(object)
|
53
|
+
duplication.map!{ |e| dup(e) }
|
54
|
+
end
|
55
|
+
|
56
|
+
def dup_hash(object)
|
57
|
+
duplication = dup_object(object)
|
58
|
+
object.reduce(duplication) { |hash, (k, v)| hash.merge!(dup(k) => dup(v)) }
|
59
|
+
end
|
60
|
+
|
61
|
+
def dup_range(range)
|
62
|
+
registration(range, range.class.new(dup(range.first), dup(range.last)))
|
63
|
+
rescue
|
64
|
+
registration(range, range.dup)
|
65
|
+
end
|
66
|
+
|
67
|
+
def dup_struct(struct)
|
68
|
+
duplication = registration(struct, struct.dup)
|
69
|
+
|
70
|
+
struct.each_pair do |attr, value|
|
71
|
+
duplication.__send__("#{attr}=", dup(value))
|
72
|
+
end
|
73
|
+
|
74
|
+
duplication
|
75
|
+
end
|
76
|
+
|
77
|
+
def dup_object(object)
|
78
|
+
dup_instance_variables(object, registration(object, object.dup))
|
79
|
+
end
|
80
|
+
|
81
|
+
def dup_instance_variables(object, duplicate)
|
82
|
+
object.instance_variables.each do |instance_variable|
|
83
|
+
value = object.instance_variable_get(instance_variable)
|
84
|
+
duplicate.instance_variable_set(instance_variable, dup(value))
|
85
|
+
end
|
86
|
+
|
87
|
+
return duplicate
|
88
|
+
end
|
89
|
+
|
90
|
+
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:
|
4
|
+
version: 3.0.0.alpha
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Luzsi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -86,13 +86,12 @@ files:
|
|
86
86
|
- Rakefile
|
87
87
|
- VERSION
|
88
88
|
- Vagrantfile
|
89
|
-
- bin/console
|
90
|
-
- bin/setup
|
91
89
|
- lib/rack/app.rb
|
92
90
|
- lib/rack/app/constants.rb
|
93
91
|
- lib/rack/app/endpoint.rb
|
94
92
|
- lib/rack/app/endpoint/not_found.rb
|
95
93
|
- lib/rack/app/error_handler.rb
|
94
|
+
- lib/rack/app/extension.rb
|
96
95
|
- lib/rack/app/file_server.rb
|
97
96
|
- lib/rack/app/instance_methods.rb
|
98
97
|
- lib/rack/app/instance_methods/core.rb
|
@@ -112,10 +111,12 @@ files:
|
|
112
111
|
- lib/rack/app/singleton_methods/mounting.rb
|
113
112
|
- lib/rack/app/singleton_methods/rack_interface.rb
|
114
113
|
- lib/rack/app/singleton_methods/route_handling.rb
|
115
|
-
- lib/rack/app/singleton_methods/
|
114
|
+
- lib/rack/app/singleton_methods/settings.rb
|
116
115
|
- lib/rack/app/test.rb
|
116
|
+
- lib/rack/app/test/singleton_methods.rb
|
117
117
|
- lib/rack/app/test/utils.rb
|
118
118
|
- lib/rack/app/utils.rb
|
119
|
+
- lib/rack/app/utils/deep_dup.rb
|
119
120
|
- lib/rack/app/version.rb
|
120
121
|
- rack-app.gemspec
|
121
122
|
homepage: http://www.rack-app.com/
|
@@ -133,9 +134,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
133
134
|
version: '0'
|
134
135
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
136
|
requirements:
|
136
|
-
- - "
|
137
|
+
- - ">"
|
137
138
|
- !ruby/object:Gem::Version
|
138
|
-
version:
|
139
|
+
version: 1.3.1
|
139
140
|
requirements: []
|
140
141
|
rubyforge_project:
|
141
142
|
rubygems_version: 2.4.8
|
data/bin/console
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "bundler/setup"
|
4
|
-
require "rack/app"
|
5
|
-
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
8
|
-
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require "pry"
|
11
|
-
# Pry.start
|
12
|
-
|
13
|
-
require "irb"
|
14
|
-
IRB.start
|