roar 0.8.0 → 0.9.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.
- data/CHANGES.markdown +18 -0
- data/Gemfile +1 -7
- data/README.textile +56 -65
- data/Rakefile +1 -1
- data/TODO.markdown +1 -0
- data/lib/roar/rails/representer_methods.rb +3 -2
- data/lib/roar/representer/feature/http_verbs.rb +29 -37
- data/lib/roar/representer/feature/hypermedia.rb +78 -13
- data/lib/roar/representer/feature/model_representing.rb +19 -27
- data/lib/roar/representer/feature/transport.rb +45 -0
- data/lib/roar/representer/json.rb +43 -14
- data/lib/roar/representer/xml.rb +44 -24
- data/lib/roar/representer.rb +31 -57
- data/lib/roar/version.rb +1 -1
- data/roar.gemspec +4 -6
- data/test/Gemfile +1 -0
- data/test/dummy/config/routes.rb +1 -1
- data/test/fake_server.rb +8 -11
- data/test/http_verbs_feature_test.rb +70 -0
- data/test/hypermedia_feature_test.rb +173 -0
- data/test/integration_test.rb +63 -100
- data/test/json_representer_test.rb +41 -35
- data/test/model_representing_test.rb +24 -26
- data/test/order_representers.rb +6 -3
- data/test/representer_test.rb +38 -4
- data/test/test_helper.rb +26 -8
- data/test/transport_test.rb +10 -13
- data/test/xml_representer_test.rb +81 -101
- metadata +20 -57
- data/lib/roar/client/entity_proxy.rb +0 -58
- data/lib/roar/client/proxy.rb +0 -14
- data/lib/roar/client/transport.rb +0 -29
- data/lib/roar/model/representable.rb +0 -31
- data/lib/roar/model.rb +0 -36
- data/test/http_verbs_test.rb +0 -46
- data/test/hypermedia_test.rb +0 -35
- data/test/model_test.rb +0 -50
- data/test/proxy_test.rb +0 -89
- data/test/representable_test.rb +0 -49
- data/test/ruby_representation_test.rb +0 -144
- data/test/test_helper_test.rb +0 -59
- data/test/xml_hypermedia_test.rb +0 -47
|
@@ -1,24 +1,16 @@
|
|
|
1
1
|
require 'test_helper'
|
|
2
2
|
|
|
3
|
-
class
|
|
4
|
-
include Roar::
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
def self.model_name
|
|
8
|
-
:order
|
|
9
|
-
end
|
|
3
|
+
class ItemRepresenter
|
|
4
|
+
include Roar::Representer::XML
|
|
5
|
+
self.representation_wrap= :item
|
|
6
|
+
property :value
|
|
10
7
|
end
|
|
11
8
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
self.
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
class PositionRepresenter < Roar::Representer::XML
|
|
19
|
-
self.representation_name= :position
|
|
20
|
-
representable_property :id
|
|
21
|
-
representable_property :item, :as => ItemRepresenter
|
|
9
|
+
class PositionRepresenter
|
|
10
|
+
include Roar::Representer::XML
|
|
11
|
+
self.representation_wrap= :position
|
|
12
|
+
property :id
|
|
13
|
+
property :item, :class => ItemRepresenter
|
|
22
14
|
end
|
|
23
15
|
|
|
24
16
|
|
|
@@ -27,7 +19,10 @@ end
|
|
|
27
19
|
class XMLRepresenterUnitTest < MiniTest::Spec
|
|
28
20
|
describe "XmlRepresenter" do
|
|
29
21
|
describe "#link" do
|
|
30
|
-
class Rapper
|
|
22
|
+
class Rapper
|
|
23
|
+
include Roar::Representer::XML
|
|
24
|
+
include Roar::Representer::Feature::Hypermedia
|
|
25
|
+
|
|
31
26
|
link :self
|
|
32
27
|
link :next
|
|
33
28
|
end
|
|
@@ -37,57 +32,13 @@ class XMLRepresenterUnitTest < MiniTest::Spec
|
|
|
37
32
|
assert_equal [{:rel=>:self, :block=>nil}, {:rel=>:next, :block=>nil}], Rapper.representable_attrs.first.rel2block
|
|
38
33
|
end
|
|
39
34
|
end
|
|
40
|
-
|
|
41
|
-
describe "#from_attributes" do
|
|
42
|
-
it "accepts a block" do
|
|
43
|
-
@c = Class.new(Roar::Representer::XML) do
|
|
44
|
-
attr_accessor :name
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
assert_equal("Conan", @c.from_attributes({}) { |rep| rep.name = "Conan" }.name)
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
35
|
end
|
|
51
36
|
end
|
|
52
37
|
|
|
53
|
-
class LinksDefinitionTest < MiniTest::Spec
|
|
54
|
-
describe "LinksDefinition" do
|
|
55
|
-
before do
|
|
56
|
-
@d = Roar::Representer::LinksDefinition.new(:links)
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
it "accepts options in constructor" do
|
|
60
|
-
assert_equal [], @d.rel2block
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
it "accepts configuration" do
|
|
64
|
-
@d.rel2block << {:rel => :self}
|
|
65
|
-
assert_equal [{:rel=>:self}], @d.rel2block
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
class XMLDefinitionTest < MiniTest::Spec
|
|
71
|
-
class Rapper
|
|
72
|
-
attr_accessor :name
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
describe "ROXML::Definition" do
|
|
76
|
-
it "responds to #populate" do
|
|
77
|
-
@r = Rapper.new
|
|
78
|
-
Representable::Definition.new(:name).populate(@r, "name" => "Eugen")
|
|
79
|
-
assert_equal "Eugen", @r.name
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
38
|
|
|
88
39
|
class XMLRepresenterFunctionalTest < MiniTest::Spec
|
|
89
40
|
class GreedyOrder
|
|
90
|
-
include
|
|
41
|
+
include TestModel
|
|
91
42
|
accessors :id, :items
|
|
92
43
|
|
|
93
44
|
def self.model_name
|
|
@@ -95,9 +46,10 @@ class XMLRepresenterFunctionalTest < MiniTest::Spec
|
|
|
95
46
|
end
|
|
96
47
|
end
|
|
97
48
|
|
|
98
|
-
class TestXmlRepresenter
|
|
99
|
-
|
|
100
|
-
|
|
49
|
+
class TestXmlRepresenter
|
|
50
|
+
include Roar::Representer::XML
|
|
51
|
+
self.representation_wrap= :order
|
|
52
|
+
property :id
|
|
101
53
|
end
|
|
102
54
|
|
|
103
55
|
|
|
@@ -110,18 +62,6 @@ class XMLRepresenterFunctionalTest < MiniTest::Spec
|
|
|
110
62
|
@i.value = "Beer"
|
|
111
63
|
end
|
|
112
64
|
|
|
113
|
-
describe "#from_attributes" do
|
|
114
|
-
it "copies represented attributes, only" do
|
|
115
|
-
@r = PositionRepresenter.from_attributes("id" => 1, "item" => @i, "unknown" => 1)
|
|
116
|
-
assert_kind_of PositionRepresenter, @r
|
|
117
|
-
assert_equal 1, @r.id
|
|
118
|
-
|
|
119
|
-
assert_kind_of ItemRepresenter, @r.item
|
|
120
|
-
assert_equal @r.item.value, "Beer"
|
|
121
|
-
end
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
|
|
125
65
|
describe "#to_attributes" do
|
|
126
66
|
it "returns a nested attributes hash" do
|
|
127
67
|
@r = PositionRepresenter.from_attributes("id" => 1, "item" => @i)
|
|
@@ -131,30 +71,68 @@ class XMLRepresenterFunctionalTest < MiniTest::Spec
|
|
|
131
71
|
|
|
132
72
|
|
|
133
73
|
describe "#to_xml" do
|
|
134
|
-
it "serializes the
|
|
135
|
-
assert_xml_equal "<order/>", @r.to_xml
|
|
74
|
+
it "serializes the model" do
|
|
75
|
+
assert_xml_equal "<order/>", @r.to_xml
|
|
76
|
+
|
|
77
|
+
@r.id = 1
|
|
78
|
+
assert_xml_equal "<order><id>1</id></order>", @r.to_xml
|
|
136
79
|
|
|
137
80
|
@r.id = 2
|
|
138
|
-
assert_xml_equal "<rap><id>2</id></rap>", @r.to_xml(:
|
|
81
|
+
assert_xml_equal "<rap><id>2</id></rap>", @r.to_xml(:wrap => :rap)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
it "is aliased by #serialize" do
|
|
85
|
+
assert_equal @r.to_xml, @r.serialize
|
|
139
86
|
end
|
|
140
87
|
end
|
|
141
88
|
|
|
89
|
+
describe "#from_xml" do
|
|
90
|
+
it "deserializes object" do
|
|
91
|
+
@order = Order.new.from_xml("<order><id>1</id></order>")
|
|
92
|
+
assert_equal "1", @order.id
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
it "is aliased by #deserialize" do
|
|
96
|
+
@order = Order.new.deserialize("<order><id>1</id></order>")
|
|
97
|
+
assert_equal "1", @order.id
|
|
98
|
+
end
|
|
99
|
+
end
|
|
142
100
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
101
|
+
|
|
102
|
+
describe "XML.from_xml" do
|
|
103
|
+
class Order
|
|
104
|
+
include Roar::Representer::XML
|
|
105
|
+
property :id
|
|
106
|
+
property :pending
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
it "is aliased to #deserialize" do
|
|
110
|
+
assert_equal TestXmlRepresenter.from_xml("<order/>").to_attributes, TestXmlRepresenter.deserialize("<order/>").to_attributes
|
|
147
111
|
end
|
|
148
112
|
|
|
113
|
+
it "accepts :except option" do
|
|
114
|
+
order = Order.from_xml(%{<order><id>1</id><pending>1</pending></order>}, :except => [:id])
|
|
115
|
+
assert_equal nil, order.id
|
|
116
|
+
assert_equal "1", order.pending
|
|
117
|
+
end
|
|
149
118
|
|
|
119
|
+
it "accepts :include option" do
|
|
120
|
+
order = Order.from_xml(%{<order><id>1</id><pending>1</pending></order>}, :include => [:id])
|
|
121
|
+
assert_equal "1", order.id
|
|
122
|
+
assert_equal nil, order.pending
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
describe "without options" do
|
|
150
128
|
it ".from_xml returns the deserialized model" do
|
|
151
|
-
@m = TestXmlRepresenter.
|
|
129
|
+
@m = TestXmlRepresenter.from_xml("<order><id>1</id></order>")
|
|
152
130
|
assert_equal "1", @m.id
|
|
153
131
|
end
|
|
154
132
|
|
|
155
|
-
it ".from_xml still works with nil" do
|
|
156
|
-
|
|
157
|
-
end
|
|
133
|
+
#it ".from_xml still works with nil" do
|
|
134
|
+
# assert TestXmlRepresenter.from_xml(nil)
|
|
135
|
+
#end
|
|
158
136
|
|
|
159
137
|
end
|
|
160
138
|
|
|
@@ -165,16 +143,16 @@ class XMLRepresenterFunctionalTest < MiniTest::Spec
|
|
|
165
143
|
end
|
|
166
144
|
|
|
167
145
|
it "#serialize skips empty :item" do
|
|
168
|
-
assert_xml_equal "<position><id>1</id></position>", @r.
|
|
146
|
+
assert_xml_equal "<position><id>1</id></position>", @r.to_xml
|
|
169
147
|
end
|
|
170
148
|
|
|
171
149
|
it "#to_xml delegates to ItemRepresenter#to_xml" do
|
|
172
150
|
@r.item = @i
|
|
173
|
-
assert_xml_equal "<position><id>1</id><item><value>Beer</value></item></position>", @r.
|
|
151
|
+
assert_xml_equal "<position><id>1</id><item><value>Beer</value></item></position>", @r.to_xml
|
|
174
152
|
end
|
|
175
153
|
|
|
176
154
|
it ".from_xml typecasts :item" do
|
|
177
|
-
@m = PositionRepresenter.
|
|
155
|
+
@m = PositionRepresenter.from_xml("<position><id>1</id><item><value>beer</value></item>\n</position>")
|
|
178
156
|
|
|
179
157
|
assert_equal "1", @m.id
|
|
180
158
|
assert_equal "beer", @m.item.value
|
|
@@ -184,28 +162,30 @@ class XMLRepresenterFunctionalTest < MiniTest::Spec
|
|
|
184
162
|
|
|
185
163
|
describe "with a typed list" do
|
|
186
164
|
before do
|
|
187
|
-
@c = Class.new
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
165
|
+
@c = Class.new do
|
|
166
|
+
include Roar::Representer::XML
|
|
167
|
+
|
|
168
|
+
self.representation_wrap= :order
|
|
169
|
+
property :id
|
|
170
|
+
collection :items, :class => ItemRepresenter, :from => :item
|
|
191
171
|
end
|
|
192
172
|
|
|
193
173
|
@r = @c.from_attributes("id" => 1)
|
|
194
174
|
end
|
|
195
175
|
|
|
196
176
|
it "#serialize_model skips empty :item" do
|
|
197
|
-
assert_xml_equal "<order><id>1</id></order>", @r.
|
|
177
|
+
assert_xml_equal "<order><id>1</id></order>", @r.to_xml
|
|
198
178
|
end
|
|
199
179
|
|
|
200
180
|
it "#serialize delegates to ItemXmlRepresenter#to_xml in list" do
|
|
201
181
|
@r.items = [ItemRepresenter.from_attributes("value" => "Bier")]
|
|
202
182
|
|
|
203
183
|
assert_xml_equal "<order><id>1</id><item><value>Bier</value></item></order>",
|
|
204
|
-
@r.
|
|
184
|
+
@r.to_xml
|
|
205
185
|
end
|
|
206
186
|
|
|
207
187
|
it ".from_xml typecasts list" do
|
|
208
|
-
@m = @c.
|
|
188
|
+
@m = @c.from_xml("<order><id>1</id><item><value>beer</value></item>\n</order>")
|
|
209
189
|
|
|
210
190
|
assert_equal "1", @m.id
|
|
211
191
|
assert_equal 1, @m.items.size
|
|
@@ -222,8 +202,8 @@ class XmlHyperlinkRepresenterTest < MiniTest::Spec
|
|
|
222
202
|
@l = Roar::Representer::XML::Hyperlink.from_xml(%{<link rel="self" href="http://roar.apotomo.de"/>})
|
|
223
203
|
end
|
|
224
204
|
|
|
225
|
-
it "responds to #
|
|
226
|
-
|
|
205
|
+
it "responds to #to_xml" do
|
|
206
|
+
assert_xml_equal %{<link rel=\"self\" href=\"http://roar.apotomo.de\"/>}, @l.to_xml
|
|
227
207
|
end
|
|
228
208
|
|
|
229
209
|
|
metadata
CHANGED
|
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
|
4
4
|
prerelease: false
|
|
5
5
|
segments:
|
|
6
6
|
- 0
|
|
7
|
-
-
|
|
7
|
+
- 9
|
|
8
8
|
- 0
|
|
9
|
-
version: 0.
|
|
9
|
+
version: 0.9.0
|
|
10
10
|
platform: ruby
|
|
11
11
|
authors:
|
|
12
12
|
- Nick Sutterer
|
|
@@ -14,41 +14,27 @@ autorequire:
|
|
|
14
14
|
bindir: bin
|
|
15
15
|
cert_chain: []
|
|
16
16
|
|
|
17
|
-
date: 2011-
|
|
17
|
+
date: 2011-12-20 00:00:00 +01:00
|
|
18
18
|
default_executable:
|
|
19
19
|
dependencies:
|
|
20
20
|
- !ruby/object:Gem::Dependency
|
|
21
21
|
name: representable
|
|
22
22
|
prerelease: false
|
|
23
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
|
24
|
-
none: false
|
|
25
|
-
requirements:
|
|
26
|
-
- - ">="
|
|
27
|
-
- !ruby/object:Gem::Version
|
|
28
|
-
segments:
|
|
29
|
-
- 0
|
|
30
|
-
version: "0"
|
|
31
|
-
type: :runtime
|
|
32
|
-
version_requirements: *id001
|
|
33
|
-
- !ruby/object:Gem::Dependency
|
|
34
|
-
name: restfulie
|
|
35
|
-
prerelease: false
|
|
36
|
-
requirement: &id002 !ruby/object:Gem::Requirement
|
|
37
24
|
none: false
|
|
38
25
|
requirements:
|
|
39
26
|
- - ~>
|
|
40
27
|
- !ruby/object:Gem::Version
|
|
41
28
|
segments:
|
|
42
|
-
- 1
|
|
43
|
-
- 0
|
|
44
29
|
- 0
|
|
45
|
-
|
|
30
|
+
- 12
|
|
31
|
+
version: "0.12"
|
|
46
32
|
type: :runtime
|
|
47
|
-
version_requirements: *
|
|
33
|
+
version_requirements: *id001
|
|
48
34
|
- !ruby/object:Gem::Dependency
|
|
49
35
|
name: hooks
|
|
50
36
|
prerelease: false
|
|
51
|
-
requirement: &
|
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
|
52
38
|
none: false
|
|
53
39
|
requirements:
|
|
54
40
|
- - ~>
|
|
@@ -59,11 +45,11 @@ dependencies:
|
|
|
59
45
|
- 4
|
|
60
46
|
version: 0.1.4
|
|
61
47
|
type: :runtime
|
|
62
|
-
version_requirements: *
|
|
48
|
+
version_requirements: *id002
|
|
63
49
|
- !ruby/object:Gem::Dependency
|
|
64
50
|
name: test_xml
|
|
65
51
|
prerelease: false
|
|
66
|
-
requirement: &
|
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
|
67
53
|
none: false
|
|
68
54
|
requirements:
|
|
69
55
|
- - ">="
|
|
@@ -71,12 +57,12 @@ dependencies:
|
|
|
71
57
|
segments:
|
|
72
58
|
- 0
|
|
73
59
|
version: "0"
|
|
74
|
-
type: :
|
|
75
|
-
version_requirements: *
|
|
60
|
+
type: :development
|
|
61
|
+
version_requirements: *id003
|
|
76
62
|
- !ruby/object:Gem::Dependency
|
|
77
63
|
name: minitest
|
|
78
64
|
prerelease: false
|
|
79
|
-
requirement: &
|
|
65
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
|
80
66
|
none: false
|
|
81
67
|
requirements:
|
|
82
68
|
- - ~>
|
|
@@ -87,11 +73,11 @@ dependencies:
|
|
|
87
73
|
- 0
|
|
88
74
|
version: 1.6.0
|
|
89
75
|
type: :development
|
|
90
|
-
version_requirements: *
|
|
76
|
+
version_requirements: *id004
|
|
91
77
|
- !ruby/object:Gem::Dependency
|
|
92
78
|
name: sinatra
|
|
93
79
|
prerelease: false
|
|
94
|
-
requirement: &
|
|
80
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
|
95
81
|
none: false
|
|
96
82
|
requirements:
|
|
97
83
|
- - ~>
|
|
@@ -102,22 +88,7 @@ dependencies:
|
|
|
102
88
|
- 6
|
|
103
89
|
version: 1.2.6
|
|
104
90
|
type: :development
|
|
105
|
-
version_requirements: *
|
|
106
|
-
- !ruby/object:Gem::Dependency
|
|
107
|
-
name: sinatra-reloader
|
|
108
|
-
prerelease: false
|
|
109
|
-
requirement: &id007 !ruby/object:Gem::Requirement
|
|
110
|
-
none: false
|
|
111
|
-
requirements:
|
|
112
|
-
- - ~>
|
|
113
|
-
- !ruby/object:Gem::Version
|
|
114
|
-
segments:
|
|
115
|
-
- 0
|
|
116
|
-
- 5
|
|
117
|
-
- 0
|
|
118
|
-
version: 0.5.0
|
|
119
|
-
type: :development
|
|
120
|
-
version_requirements: *id007
|
|
91
|
+
version_requirements: *id005
|
|
121
92
|
description: Streamlines the development of RESTful, resource-oriented architectures in Ruby.
|
|
122
93
|
email:
|
|
123
94
|
- apotonick@gmail.com
|
|
@@ -129,15 +100,12 @@ extra_rdoc_files: []
|
|
|
129
100
|
|
|
130
101
|
files:
|
|
131
102
|
- .gitignore
|
|
103
|
+
- CHANGES.markdown
|
|
132
104
|
- Gemfile
|
|
133
105
|
- README.textile
|
|
134
106
|
- Rakefile
|
|
107
|
+
- TODO.markdown
|
|
135
108
|
- lib/roar.rb
|
|
136
|
-
- lib/roar/client/entity_proxy.rb
|
|
137
|
-
- lib/roar/client/proxy.rb
|
|
138
|
-
- lib/roar/client/transport.rb
|
|
139
|
-
- lib/roar/model.rb
|
|
140
|
-
- lib/roar/model/representable.rb
|
|
141
109
|
- lib/roar/rails.rb
|
|
142
110
|
- lib/roar/rails/controller_methods.rb
|
|
143
111
|
- lib/roar/rails/representer_methods.rb
|
|
@@ -146,6 +114,7 @@ files:
|
|
|
146
114
|
- lib/roar/representer/feature/http_verbs.rb
|
|
147
115
|
- lib/roar/representer/feature/hypermedia.rb
|
|
148
116
|
- lib/roar/representer/feature/model_representing.rb
|
|
117
|
+
- lib/roar/representer/feature/transport.rb
|
|
149
118
|
- lib/roar/representer/json.rb
|
|
150
119
|
- lib/roar/representer/xml.rb
|
|
151
120
|
- lib/roar/version.rb
|
|
@@ -187,23 +156,17 @@ files:
|
|
|
187
156
|
- test/dummy/tmp/app/cells/blog/post/latest.html.erb
|
|
188
157
|
- test/dummy/tmp/app/cells/blog/post_cell.rb
|
|
189
158
|
- test/fake_server.rb
|
|
190
|
-
- test/
|
|
191
|
-
- test/
|
|
159
|
+
- test/http_verbs_feature_test.rb
|
|
160
|
+
- test/hypermedia_feature_test.rb
|
|
192
161
|
- test/integration_test.rb
|
|
193
162
|
- test/json_representer_test.rb
|
|
194
163
|
- test/model_representing_test.rb
|
|
195
|
-
- test/model_test.rb
|
|
196
164
|
- test/order_representers.rb
|
|
197
|
-
- test/proxy_test.rb
|
|
198
165
|
- test/rails/controller_methods_test.rb
|
|
199
166
|
- test/rails/rails_representer_methods_test.rb
|
|
200
|
-
- test/representable_test.rb
|
|
201
167
|
- test/representer_test.rb
|
|
202
|
-
- test/ruby_representation_test.rb
|
|
203
168
|
- test/test_helper.rb
|
|
204
|
-
- test/test_helper_test.rb
|
|
205
169
|
- test/transport_test.rb
|
|
206
|
-
- test/xml_hypermedia_test.rb
|
|
207
170
|
- test/xml_representer_test.rb
|
|
208
171
|
has_rdoc: true
|
|
209
172
|
homepage: http://rubygems.org/gems/roar
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
require "roar/model"
|
|
2
|
-
require "roar/representer/xml"
|
|
3
|
-
require "active_support/core_ext/module/attr_internal"
|
|
4
|
-
require "roar/client/proxy"
|
|
5
|
-
|
|
6
|
-
module Roar
|
|
7
|
-
module Client
|
|
8
|
-
# Wraps associated objects, they can be retrieved with #finalize!
|
|
9
|
-
# Used e.g. in Representer::Xml.has_proxied.
|
|
10
|
-
class EntityProxy
|
|
11
|
-
# FIXME: where to move me? i do Representable and i use Transport. however, i'm only for clients.
|
|
12
|
-
include Model
|
|
13
|
-
include Representer::Xml # FIXME: why does EntityProxy know about xml? get this from Representable or so.
|
|
14
|
-
extend Proxy
|
|
15
|
-
|
|
16
|
-
attr_internal :proxied_resource
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
class << self
|
|
21
|
-
attr_accessor :options
|
|
22
|
-
|
|
23
|
-
def class_for(options)
|
|
24
|
-
Class.new(self).tap { |k| k.options = options }
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def model_name
|
|
28
|
-
options[:class].model_name # proxy!
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def from_attributes(attrs) # FIXME: move to Representable or so.
|
|
32
|
-
new(attrs)
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
# Get the actual proxied resource.
|
|
37
|
-
def finalize!(*)
|
|
38
|
-
# TODO: move to class.
|
|
39
|
-
# DISCUSS: how to compute uri? what if NO uri passed? exception?
|
|
40
|
-
self.proxied_resource = self.class.get_model(original_attributes["uri"], self.class.options[:class])
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def attributes
|
|
44
|
-
# DISCUSS: delegate all unknown methods to the proxied object?
|
|
45
|
-
proxied_resource.attributes # proxy!
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
def attributes_for_xml(*options)
|
|
49
|
-
original_attributes
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
private
|
|
53
|
-
def original_attributes
|
|
54
|
-
@attributes
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
end
|
data/lib/roar/client/proxy.rb
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
module Roar
|
|
2
|
-
module Client
|
|
3
|
-
|
|
4
|
-
module Proxy
|
|
5
|
-
include Transport
|
|
6
|
-
|
|
7
|
-
def get_model(uri, klass) # DISCUSS: not directly used in models. USED in EntityProxy.
|
|
8
|
-
body = get_uri(uri).body
|
|
9
|
-
klass.from_xml(body) # DISCUSS: knows about DE-serialization and representation-type!
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
end
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
require "restfulie"
|
|
2
|
-
|
|
3
|
-
module Roar
|
|
4
|
-
module Client
|
|
5
|
-
# Implements the HTTP verbs by abstracting Restfulie.
|
|
6
|
-
module Transport
|
|
7
|
-
# TODO: generically handle return codes/let Restfulie do it.
|
|
8
|
-
def get_uri(uri, as)
|
|
9
|
-
Restfulie.at(uri).accepts(as).get # TODO: debugging/logging here.
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def post_uri(uri, body, as)
|
|
13
|
-
Restfulie.at(uri).as(as).post(body)
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def put_uri(uri, body, as)
|
|
17
|
-
Restfulie.at(uri).as(as).put(body)
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def patch_uri(uri, body, as)
|
|
21
|
-
Restfulie.at(uri).as(as).patch(body)
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def delete_uri(uri, as)
|
|
25
|
-
Restfulie.at(uri).accepts(as).delete # TODO: debugging/logging here.
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
module Roar
|
|
2
|
-
module Model
|
|
3
|
-
module Representable
|
|
4
|
-
extend ActiveSupport::Concern
|
|
5
|
-
|
|
6
|
-
included do |base|
|
|
7
|
-
base.extend Hooks::InheritableAttribute
|
|
8
|
-
base.inheritable_attr :representable
|
|
9
|
-
base.representable = {} # FIXME: doesn't that break inheritance?
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
module ClassMethods
|
|
13
|
-
def represents(mime_type, options)
|
|
14
|
-
self.representable[mime_type] = options[:with]
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def representer_class_for(mime_type)
|
|
18
|
-
representable[mime_type]
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def from(mime_type, representation)
|
|
22
|
-
representer_class_for(mime_type).deserialize(self, mime_type, representation)
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def to(mime_type)
|
|
27
|
-
self.class.representer_class_for(mime_type).new.serialize(self, mime_type)
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
end
|
data/lib/roar/model.rb
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
module Roar
|
|
2
|
-
# Basic methods needed to implement the ActiveModel API. Gives your model +#attributes+ and +model_name+.
|
|
3
|
-
# Include this for quickly converting an object to a ROAR-compatible monster.
|
|
4
|
-
#
|
|
5
|
-
# #DISCUSS: are Models used both on client- and server-side? I'd say hell yeah.
|
|
6
|
-
module Model
|
|
7
|
-
extend ActiveSupport::Concern
|
|
8
|
-
|
|
9
|
-
module ClassMethods
|
|
10
|
-
def model_name
|
|
11
|
-
ActiveSupport::Inflector.underscore(self) # We don't use AM::Naming for now.
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def accessors(*names)
|
|
15
|
-
names.each do |name|
|
|
16
|
-
class_eval %Q{
|
|
17
|
-
def #{name}=(v)
|
|
18
|
-
attributes["#{name}"] = v
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def #{name}
|
|
22
|
-
attributes["#{name}"]
|
|
23
|
-
end
|
|
24
|
-
}
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
attr_accessor :attributes
|
|
31
|
-
|
|
32
|
-
def initialize(attributes={})
|
|
33
|
-
@attributes = attributes
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|
data/test/http_verbs_test.rb
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
require 'test_helper'
|
|
2
|
-
require 'roar/representer/feature/http_verbs'
|
|
3
|
-
|
|
4
|
-
class HttpVerbsTest < MiniTest::Spec
|
|
5
|
-
class BandRepresenter < Roar::Representer::XML
|
|
6
|
-
self.representation_name = :band
|
|
7
|
-
|
|
8
|
-
property :name
|
|
9
|
-
property :label
|
|
10
|
-
|
|
11
|
-
include Roar::Representer::Feature::HttpVerbs
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
describe "HttpVerbs" do
|
|
15
|
-
before do
|
|
16
|
-
@r = BandRepresenter.new
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
# TODO: assert that Restfulie#post receives the correct document.
|
|
20
|
-
|
|
21
|
-
it "#post deserializes the incoming representation and returns it" do
|
|
22
|
-
@r.name = "Strung Out"
|
|
23
|
-
rep = @r.post("http://localhost:9999/band", "application/xml")
|
|
24
|
-
assert_equal "Strung Out", rep.name
|
|
25
|
-
assert_equal "n/a", rep.label
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
it "#post! deserializes the incoming representation and replaces attributes" do
|
|
29
|
-
@r.name = "Strung Out"
|
|
30
|
-
assert_equal nil, @r.label
|
|
31
|
-
@r.post!("http://localhost:9999/band", "application/xml")
|
|
32
|
-
assert_equal "Strung Out", @r.name
|
|
33
|
-
assert_equal "n/a", @r.label
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
it "#put deserializes the incoming representation and returns it" do
|
|
39
|
-
@r.name = "Strung Out"
|
|
40
|
-
@r.label = "Fat Wreck"
|
|
41
|
-
rep = @r.put("http://localhost:9999/band/strungout", "application/xml")
|
|
42
|
-
assert_equal "Strung Out", rep.name
|
|
43
|
-
assert_equal "Fat Wreck", rep.label
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
end
|