http_event_logger 0.1.0.rc2 → 0.1.0.rc3

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: 5bd3bebcc3b5665faa4689a9baa85c01c1021527
4
- data.tar.gz: c405a28f0576ebbb46fa24f41c2e23c0dbbe1d3f
3
+ metadata.gz: de9d42502d6b49be918870c4d4d7cc56d34409a2
4
+ data.tar.gz: 3354bf5b60ff429421f73af05b5132b23f5551fd
5
5
  SHA512:
6
- metadata.gz: ce05d87946e07222ac313134ece1ec2b9891f829222710087c9e682ff0ddec1a90b36d2040caf5c794c9cd67b8715422081b7bfbb2510ae27249141b30fdc3b3
7
- data.tar.gz: afc39c1939139a2565ffc45003823f8e45f1f1da9231f525a94a51be81f78cf78a3e7f79640a6883297b75d0e0f99602638e69291d21afe9f72db7e26748da3c
6
+ metadata.gz: 1cb7fff0c4f5aa0d589d3129c8c368fcc0a3984337b7b9eba02f58cec8f2814e23bd49335d59bb3832b4475cb23e334171ba2a07ad4a792809665c3e43355cf8
7
+ data.tar.gz: c28540272e0a389fec2d13cb1edfac6397182dd8373cb621873a7412e4ad6631312c3ef75dbca4fe0a0d6127cd07656682f90e1a7265add2fa7684bbbfe2263a
@@ -4,7 +4,7 @@ module HttpEventLogger
4
4
  class Headers
5
5
 
6
6
  def initialize(headers)
7
- @headers = headers || ""
7
+ @headers = headers.is_a?(Hash) ? headers : to_hash_if_possible(headers)
8
8
  end
9
9
 
10
10
  def [](name)
@@ -12,11 +12,22 @@ module HttpEventLogger
12
12
  end
13
13
 
14
14
  def to_s
15
- @headers.is_a?(String) ? @headers : @headers.map { |key, value| "#{key}: #{value}" }.join(", ")
15
+ @headers.is_a?(Hash) ? @headers.map { |key, value| "#{key}: #{value}" }.join(", ") : @headers
16
16
  end
17
17
 
18
18
  private
19
19
 
20
+ def to_hash_if_possible(headers)
21
+ if headers.respond_to?(:reduce)
22
+ headers.reduce({}) do |hash, header|
23
+ hash[header[0]] = header[1]
24
+ hash
25
+ end
26
+ else
27
+ headers
28
+ end
29
+ end
30
+
20
31
  def header_value_for(name)
21
32
  header = @headers.find { |key, value| key.downcase == name.downcase }
22
33
  header ? header[1] : nil
@@ -1,3 +1,3 @@
1
1
  module HttpEventLogger
2
- VERSION = "0.1.0.rc2".freeze
2
+ VERSION = "0.1.0.rc3".freeze
3
3
  end
@@ -44,6 +44,48 @@ describe HttpEventLogger::Event::Headers do
44
44
 
45
45
  end
46
46
 
47
+ context "when an enumerable is provided" do
48
+
49
+ let(:provided_headers) { [ [ "some_key", "some value" ], [ "some_other_key", "some other value" ] ].to_enum }
50
+
51
+ describe "#[]" do
52
+
53
+ context "and the name provided exactly matches a header name" do
54
+
55
+ it "returns the value of the header" do
56
+ expect(headers["some_key"]).to eql("some value")
57
+ end
58
+
59
+ end
60
+
61
+ context "and the name provided is a case insensitive match for a header name" do
62
+
63
+ it "returns the value of the header" do
64
+ expect(headers["Some_Key"]).to eql("some value")
65
+ end
66
+
67
+ end
68
+
69
+ context "and the the name provided does not match a header name" do
70
+
71
+ it "returns nil" do
72
+ expect(headers["does_not_match"]).to eql(nil)
73
+ end
74
+
75
+ end
76
+
77
+ end
78
+
79
+ describe "#to_s" do
80
+
81
+ it "returns a string containing all header keys and values" do
82
+ expect(headers.to_s).to eql("some_key: some value, some_other_key: some other value")
83
+ end
84
+
85
+ end
86
+
87
+ end
88
+
47
89
  context "when a string is provided" do
48
90
 
49
91
  let(:provided_headers) { "some_key some value" }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: http_event_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.rc2
4
+ version: 0.1.0.rc3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Ueckerman