rack-app 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/VERSION +1 -1
- data/lib/rack/app.rb +6 -6
- data/lib/rack/app/endpoint.rb +6 -1
- data/lib/rack/app/request_helper/params.rb +19 -18
- data/lib/rack/app/request_helpers.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d3ec73ef1741248aea0a795217bb718ad9aee4a5
|
4
|
+
data.tar.gz: bee58d13e8db2f14d1ed1bb7b0f06fb6c0429def
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 17bdeed0847c57119871824c6eea1defa58a51c595dada79153fa0d1d0d68db8019828a390b20d4d4c29be5d87c383dc45ff5297afad3d3a544a9ce10c39d1b4
|
7
|
+
data.tar.gz: 913db22c6134df5b7c6213dc7d07bafb9e71bc2d6966e401ab482f5aab76ad62f385a5937ae6f43149815b52133b867a54b6119fb5ac728a05642e269e28f06f
|
data/Gemfile.lock
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
data/lib/rack/app.rb
CHANGED
@@ -22,14 +22,14 @@ class Rack::App
|
|
22
22
|
Rack::App::Runner.response_for(self,request_env)
|
23
23
|
end
|
24
24
|
|
25
|
-
|
25
|
+
attr_writer :request, :response
|
26
26
|
|
27
|
-
|
27
|
+
def request
|
28
|
+
@request || raise("request object is not set for #{self.class}")
|
29
|
+
end
|
28
30
|
|
29
|
-
def
|
30
|
-
@response
|
31
|
-
@request = request
|
32
|
-
@options = options
|
31
|
+
def response
|
32
|
+
@response || raise("response object is not set for #{self.class}")
|
33
33
|
end
|
34
34
|
|
35
35
|
end
|
data/lib/rack/app/endpoint.rb
CHANGED
@@ -12,7 +12,12 @@ class Rack::App::Endpoint
|
|
12
12
|
request = Rack::Request.new(request_env)
|
13
13
|
response = Rack::Response.new
|
14
14
|
|
15
|
-
request_handler = @api_class.new
|
15
|
+
request_handler = @api_class.new
|
16
|
+
|
17
|
+
request_handler.request = request
|
18
|
+
request_handler.response = response
|
19
|
+
request.env['rack.app.path_params_matcher']= @path_params_matcher.dup
|
20
|
+
|
16
21
|
call_return = request_handler.instance_exec(&@logic_block)
|
17
22
|
|
18
23
|
return call_return if is_a_rack_response_finish?(call_return)
|
@@ -1,10 +1,8 @@
|
|
1
1
|
require 'cgi'
|
2
2
|
class Rack::App::RequestHelpers::Params
|
3
3
|
|
4
|
-
def initialize(request_env
|
4
|
+
def initialize(request_env)
|
5
5
|
@request_env = request_env
|
6
|
-
|
7
|
-
@path_params_matcher = options[:path_params_matcher] || {}
|
8
6
|
end
|
9
7
|
|
10
8
|
def to_hash
|
@@ -14,36 +12,39 @@ class Rack::App::RequestHelpers::Params
|
|
14
12
|
protected
|
15
13
|
|
16
14
|
def query_params
|
17
|
-
CGI.parse(@request_env[
|
15
|
+
CGI.parse(@request_env[Rack::QUERY_STRING].to_s).freeze.reduce({}) do |params_collection, (k, v)|
|
16
|
+
|
18
17
|
if v.is_a?(Array) and v.length === 1
|
19
18
|
params_collection[k]= v[0]
|
20
19
|
else
|
21
|
-
k = k.sub(/\[\]$/,'')
|
20
|
+
k = k.sub(/\[\]$/, '')
|
22
21
|
params_collection[k]= v
|
23
22
|
end
|
24
23
|
|
25
24
|
params_collection
|
25
|
+
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
|
30
29
|
def request_path_params
|
31
30
|
path_params = {}
|
32
|
-
|
33
|
-
|
34
|
-
|
31
|
+
path_params.merge!(extract_path_params) unless path_params_matcher.empty?
|
32
|
+
path_params
|
33
|
+
end
|
35
34
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
35
|
+
def extract_path_params
|
36
|
+
request_path_parts.each.with_index.reduce({}) do |params_col, (path_part, index)|
|
37
|
+
params_col[path_params_matcher[index]]= path_part if path_params_matcher[index]
|
38
|
+
params_col
|
39
|
+
end
|
40
|
+
end
|
42
41
|
|
43
|
-
|
42
|
+
def request_path_parts
|
43
|
+
Rack::App::Utils.normalize_path(@request_env['REQUEST_PATH']).split('/')
|
44
|
+
end
|
44
45
|
|
45
|
-
|
46
|
-
|
46
|
+
def path_params_matcher
|
47
|
+
@request_env['rack.app.path_params_matcher'] || {}
|
47
48
|
end
|
48
49
|
|
49
50
|
end
|
@@ -3,7 +3,7 @@ module Rack::App::RequestHelpers
|
|
3
3
|
require 'rack/app/request_helper/params'
|
4
4
|
|
5
5
|
def params
|
6
|
-
@__request_params__ ||= Rack::App::RequestHelpers::Params.new(request.env
|
6
|
+
@__request_params__ ||= Rack::App::RequestHelpers::Params.new(request.env).to_hash
|
7
7
|
end
|
8
8
|
|
9
9
|
def status(new_status=nil)
|
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: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Luzsi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|