rack-delegate 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3c1d5ca6de8d7bac5979e2ac16460b6a801bc313
4
- data.tar.gz: 28804039fe13751a0beaa1e18f05dede5ca5553d
3
+ metadata.gz: 635459c3a9a6f8fdfef399b29e6a8a8958be8b59
4
+ data.tar.gz: 244bba8c0cdd81896e6bebdcb9e537638e45d50d
5
5
  SHA512:
6
- metadata.gz: 58696d495777a91a8df345f57ee8eaf43ab238fbf812b9b004d2741b6680b5fc6b0bd3b2404c927a28ea7bf584781ab215dfb226efafff5885466df8ac8b61ff
7
- data.tar.gz: ee8b16bc8edcdcf0d5595bbcb7c5b22f729fb45940a3b2b2d4128698547ae88b8500175dea5c229283eb42447330e853502476966f07a9116a915a9eda1d9feb
6
+ metadata.gz: 1bae04109174577d7ace0e5af0c6e65d04a4d4bbe8e2d5a93bd634862511600d7c2228f2654e67753df1424102b1b22090321a6a30bfb8f4044616f18b5cafa5
7
+ data.tar.gz: ba625dcc76877fcff011d0db4896477ddd1e74d98bb723ff5f5210ec09fba57f9398b8c8c18ee2174b3af6fadbac789b02e9067e0c1dc89d1838d45222b3fd5f
@@ -12,6 +12,11 @@ module Rack
12
12
  autoload :Configuration, 'rack/delegate/configuration'
13
13
  autoload :Dispatcher, 'rack/delegate/dispatcher'
14
14
 
15
+ class << self
16
+ attr_accessor :network_error_response
17
+ end
18
+ self.network_error_response = NetworkErrorResponse
19
+
15
20
  def self.configure(&block)
16
21
  dispatcher = Dispatcher.configure(&block)
17
22
 
@@ -14,10 +14,11 @@ module Rack
14
14
  @constraints = []
15
15
  @rewriter = Rewriter.new
16
16
  @changer = Rewriter.new
17
+ @timeout = NetworkErrorResponse
17
18
  end
18
19
 
19
20
  def from(pattern, to:, constraints: nil)
20
- action = Action.new(pattern, Delegator.new(to, @rewriter, @changer))
21
+ action = Action.new(pattern, Delegator.new(to, @rewriter, @changer, @timeout))
21
22
  action = Rack::Timeout.new(action) if timeout?
22
23
 
23
24
  constraints = Array(constraints).concat(@constraints)
@@ -40,6 +41,11 @@ module Rack
40
41
  end
41
42
  end
42
43
 
44
+ def timeout(response_object = nil, &block)
45
+ @timeout = response_object if response_object
46
+ @timeout = block if block
47
+ end
48
+
43
49
  private
44
50
 
45
51
  def constraints(*args, &block)
@@ -3,14 +3,11 @@ require 'timeout_errors'
3
3
  module Rack
4
4
  module Delegate
5
5
  class Delegator
6
- class << self
7
- attr_accessor :network_error_response
8
- end
9
-
10
- def initialize(url, uri_rewriter, net_http_request_rewriter)
6
+ def initialize(url, uri_rewriter, net_http_request_rewriter, timeout_response)
11
7
  @url = URI(url)
12
8
  @uri_rewriter = uri_rewriter
13
9
  @net_http_request_rewriter = net_http_request_rewriter
10
+ @timeout_response = timeout_response
14
11
  end
15
12
 
16
13
  def call(env)
@@ -23,8 +20,7 @@ module Rack
23
20
 
24
21
  convert_to_rack_response(http_response)
25
22
  rescue TimeoutErrors
26
- # TODO: Should I let the error in as an input?
27
- network_error_response.call(env)
23
+ @timeout_response.call(env)
28
24
  end
29
25
 
30
26
  private
@@ -33,10 +29,6 @@ module Rack
33
29
  [@url.host, @url.port, https: @url.scheme == 'https']
34
30
  end
35
31
 
36
- def network_error_response
37
- self.class.network_error_response ||= NetworkErrorResponse
38
- end
39
-
40
32
  def convert_to_rack_response(http_response)
41
33
  status = http_response.code
42
34
  headers = normalize_headers_for(http_response)
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  module Delegate
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-delegate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Genadi Samokovarov