http-double 0.1.9 → 0.1.10

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: f23faa1f6653d54edc6a1b1584c02720859b5f56
4
- data.tar.gz: 23e07dbfc8058a0f85ac642cc6ec2b1e466743c3
3
+ metadata.gz: f2481a69325fb8b81a08f9dcc1009239536cadaf
4
+ data.tar.gz: e178067a35712c22b02e09e3bf84f71c54f88ae0
5
5
  SHA512:
6
- metadata.gz: 052c0e4cadc430e204ae4a0e00554d0eafd1d3e1f37586200bdce216dc1546907a6f45e5edacaa49374d22d014561ed71511ddfa0a99c583c269207c42f6e072
7
- data.tar.gz: 593c08637600a28ca534f2a3d6b2b51f0cc51fb04edca47dd33af0a43c2e950e76e21fd4fee60b6f2cdef5b7fbbf26371ac4a003146c31f406b8bb964a7cbee4
6
+ metadata.gz: 50b1aa2fded59adff9de2ff499191e16d2cee124e18870daf97557b820912ec7b6b13d71182278d3b0fbdb3dc0a77122ca11f1458a819efb6be19e3e4aa9b693
7
+ data.tar.gz: 3e0116b8a8470414734a885c7fc549358087e06d2d4b60466eec54cc3923b2a1cb00ad9cd21c2b6a747d58592c942b336e09f9fa25ee151a4eb0fbd52d6df5f0
@@ -1,11 +1,8 @@
1
1
  require 'rack/utils'
2
- require 'ostruct'
3
2
  require 'active_support/hash_with_indifferent_access'
4
3
 
5
4
  class HttpDouble::RequestLogger
6
-
7
- # noinspection RubyConstantNamingConvention
8
- IHash = ActiveSupport::HashWithIndifferentAccess
5
+ include ActiveSupport
9
6
 
10
7
  def initialize(app, log)
11
8
  @app = app
@@ -13,14 +10,35 @@ class HttpDouble::RequestLogger
13
10
  end
14
11
 
15
12
  def call(env)
16
- response = @app.call(env)
17
- res = OpenStruct.new(
18
- code: response[0],
19
- headers: IHash.new(response[1]),
20
- body: response[2].join
21
- )
22
- @log << OpenStruct.new(request: Request.new(env), response: res)
23
- response
13
+ @app.call(env).tap do |response|
14
+ @log << RoundTrip.new(
15
+ Request.new(env),
16
+ Response.new(
17
+ response[0],
18
+ HashWithIndifferentAccess.new(response[1]),
19
+ response[2].join
20
+ )
21
+ )
22
+ end
23
+ end
24
+
25
+ class RoundTrip
26
+ attr_reader :request, :response
27
+
28
+ def initialize(request, response)
29
+ @request = request
30
+ @response = response
31
+ end
32
+ end
33
+
34
+ class Response
35
+ attr_reader :code, :headers, :body
36
+
37
+ def initialize(code, headers, body)
38
+ @code = code
39
+ @headers = headers
40
+ @body = body
41
+ end
24
42
  end
25
43
 
26
44
  class Request
@@ -72,7 +90,11 @@ class HttpDouble::RequestLogger
72
90
  end
73
91
 
74
92
  def form_fields
75
- @form_fields ||= IHash.new(Rack::Utils.parse_query(body).map { |key, value| [key.to_sym, value.is_a?(Array) ? value : [value]] }.to_h)
93
+ @form_fields ||= HashWithIndifferentAccess.new(
94
+ Rack::Utils.parse_query(body).map do |key, value|
95
+ [key.to_sym, value.is_a?(Array) ? value : [value]]
96
+ end.to_h
97
+ )
76
98
  end
77
99
 
78
100
  def json_input
@@ -1,3 +1,3 @@
1
1
  module HttpDouble
2
- VERSION = '0.1.9'
2
+ VERSION = '0.1.10'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: http-double
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Neil E. Pearson