http_objects 0.0.1 → 0.0.2
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.
data/lib/http_objects/hash.rb
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
module HttpObjects::Parameters
|
2
2
|
|
3
3
|
# 3.7. Media Types
|
4
|
+
#
|
5
|
+
# media-type = type "/" subtype *( ";" parameter )
|
6
|
+
# type = token
|
7
|
+
# subtype = token
|
8
|
+
#
|
4
9
|
# Examples
|
5
10
|
# text/html; charset=ISO-8859-4
|
6
11
|
class MediaType
|
@@ -12,6 +17,7 @@ module HttpObjects::Parameters
|
|
12
17
|
value, params = value.split(";", 2)
|
13
18
|
|
14
19
|
parameters = {}
|
20
|
+
params = params.to_s
|
15
21
|
params.split(/\s*;\s*/).each do |param|
|
16
22
|
name, param_value = param.split(/=/)
|
17
23
|
name = name.gsub(/\s*/, "")
|
data/lib/http_objects/version.rb
CHANGED
@@ -28,7 +28,7 @@ describe HttpObjects::Hash do
|
|
28
28
|
end
|
29
29
|
it "with values" do
|
30
30
|
hash = subject.new("MyObject" => "value")
|
31
|
-
hash
|
31
|
+
hash.myobject.must_be_instance_of(MyObject)
|
32
32
|
end
|
33
33
|
it "should reuse same object" do
|
34
34
|
hash_headers = subject.new("MyObject" => "value")
|
@@ -44,13 +44,24 @@ describe HttpObjects::Hash do
|
|
44
44
|
end
|
45
45
|
it "HTTP Header value" do
|
46
46
|
subject["MyObject"] = "value"
|
47
|
-
subject
|
47
|
+
subject.myobject.must_be_instance_of(MyObject)
|
48
48
|
end
|
49
49
|
it "without value" do
|
50
50
|
subject["MyObject"].must_be_nil
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
+
describe "#[]" do
|
55
|
+
it "simple value" do
|
56
|
+
subject["chave"] = "valor"
|
57
|
+
subject["chave"].must_equal("valor")
|
58
|
+
end
|
59
|
+
it "returns value from http header" do
|
60
|
+
subject["MyObject"] = "value"
|
61
|
+
subject["MyObject"].must_equal("value")
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
54
65
|
describe "#store as alias of []=" do
|
55
66
|
it "simple value" do
|
56
67
|
subject.store("chave", "valor")
|
@@ -58,13 +69,12 @@ describe HttpObjects::Hash do
|
|
58
69
|
end
|
59
70
|
it "HTTP Header value" do
|
60
71
|
subject.store("MyObject", "value")
|
61
|
-
subject
|
72
|
+
subject.myobject.must_be_instance_of(MyObject)
|
62
73
|
end
|
63
74
|
end
|
64
75
|
|
65
76
|
it "header as instance method" do
|
66
77
|
subject.store("MyObject", "value")
|
67
|
-
subject["MyObject"].must_be_instance_of(MyObject)
|
68
78
|
|
69
79
|
subject.myobject.must_be_instance_of(MyObject)
|
70
80
|
subject.myobject?.must_equal(true)
|
@@ -1,19 +1,30 @@
|
|
1
1
|
require "test_helper"
|
2
2
|
|
3
|
-
|
3
|
+
include HttpObjects::Parameters
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
describe "text/html; charset=ISO-8859-4" do
|
8
|
-
|
9
|
-
subject { subject_class.parse("text/html; charset=ISO-8859-4") }
|
5
|
+
describe MediaType do
|
10
6
|
|
7
|
+
describe "with only type/subtype" do
|
8
|
+
subject { MediaType.parse("text/html") }
|
11
9
|
it "#raw" do
|
12
|
-
subject.raw.must_equal("text/html
|
10
|
+
subject.raw.must_equal("text/html")
|
13
11
|
end
|
14
12
|
it "#value" do
|
15
13
|
subject.value.must_equal("text/html")
|
16
14
|
end
|
15
|
+
it "#parameters" do
|
16
|
+
subject.parameters.must_be_empty
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "with type/subtype and one parameter" do
|
21
|
+
subject { MediaType.parse("application/xhtml+xml; charset=ISO-8859-4") }
|
22
|
+
it "#raw" do
|
23
|
+
subject.raw.must_equal("application/xhtml+xml; charset=ISO-8859-4")
|
24
|
+
end
|
25
|
+
it "#value" do
|
26
|
+
subject.value.must_equal("application/xhtml+xml")
|
27
|
+
end
|
17
28
|
it "#parameters" do
|
18
29
|
subject.parameters.must_equal("charset" => "ISO-8859-4")
|
19
30
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: http_objects
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Roger Leite
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-12-
|
18
|
+
date: 2012-12-19 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: rake
|