rack-app 0.3.0 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 08805ebc1c3be6338441b4ca870489333fdee27a
4
- data.tar.gz: 0fc3f607f9bbc02ed4fe4392b49968e23612015e
3
+ metadata.gz: d3ec73ef1741248aea0a795217bb718ad9aee4a5
4
+ data.tar.gz: bee58d13e8db2f14d1ed1bb7b0f06fb6c0429def
5
5
  SHA512:
6
- metadata.gz: eaa0c3dc517544bc6dee91ae97a3208a39172da520c4368c399f222e928947252ed7c87a9e9dec637d7352bc6abd616a44304331c6622419c77316f84b68d1d8
7
- data.tar.gz: ae56428e27d1ad9e30ebb9e21b215cd440d3b0cde6bb97ef8a0ddcb92a2b4b15f6390ce631bee218de7efd426af76b6330f5755301fc93669e166d266be1f35a
6
+ metadata.gz: 17bdeed0847c57119871824c6eea1defa58a51c595dada79153fa0d1d0d68db8019828a390b20d4d4c29be5d87c383dc45ff5297afad3d3a544a9ce10c39d1b4
7
+ data.tar.gz: 913db22c6134df5b7c6213dc7d07bafb9e71bc2d6966e401ab482f5aab76ad62f385a5937ae6f43149815b52133b867a54b6119fb5ac728a05642e269e28f06f
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rack-app (0.3.0)
4
+ rack-app (0.4.0)
5
5
  rack
6
6
 
7
7
  GEM
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.4.0
@@ -22,14 +22,14 @@ class Rack::App
22
22
  Rack::App::Runner.response_for(self,request_env)
23
23
  end
24
24
 
25
- attr_reader :request, :response
25
+ attr_writer :request, :response
26
26
 
27
- protected
27
+ def request
28
+ @request || raise("request object is not set for #{self.class}")
29
+ end
28
30
 
29
- def initialize(request, response,options = {})
30
- @response = 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
@@ -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(request, response,{path_params_matcher: @path_params_matcher})
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, options = {})
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['QUERY_STRING'].to_s).freeze.reduce({}) do |params_collection, (k, v)|
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
- if @path_params_matcher.is_a?(Hash) and not @path_params_matcher.empty?
33
-
34
- request_path_parts = Rack::App::Utils.normalize_path(@request_env['REQUEST_PATH']).split('/')
31
+ path_params.merge!(extract_path_params) unless path_params_matcher.empty?
32
+ path_params
33
+ end
35
34
 
36
- path_params = request_path_parts.each.with_index.reduce({}) do |params_col, (path_part, index)|
37
- if @path_params_matcher[index]
38
- params_col[@path_params_matcher[index]]= path_part
39
- end
40
- params_col
41
- end
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
- path_params.merge!(path_params)
42
+ def request_path_parts
43
+ Rack::App::Utils.normalize_path(@request_env['REQUEST_PATH']).split('/')
44
+ end
44
45
 
45
- end
46
- path_params
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,@options).to_hash
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.3.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-25 00:00:00.000000000 Z
11
+ date: 2015-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler