representable 0.0.1.alpha1 → 0.0.1

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.
Files changed (102) hide show
  1. data/README.rdoc +58 -153
  2. data/lib/representable.rb +18 -42
  3. data/lib/representable/bindings/json_bindings.rb +69 -0
  4. data/lib/representable/bindings/xml_bindings.rb +152 -0
  5. data/lib/representable/definition.rb +1 -12
  6. data/lib/representable/json.rb +66 -0
  7. data/lib/representable/version.rb +1 -1
  8. data/lib/representable/xml.rb +32 -38
  9. data/representable.gemspec +3 -2
  10. data/test/bindings_test.rb +110 -0
  11. data/test/json_test.rb +130 -0
  12. data/test/{roxml_test.rb → representable_test.rb} +28 -9
  13. data/test/test_helper.rb +2 -0
  14. data/test/xml_test.rb +192 -0
  15. metadata +32 -105
  16. data/History.txt +0 -354
  17. data/TODO +0 -37
  18. data/VERSION +0 -1
  19. data/examples/amazon.rb +0 -35
  20. data/examples/current_weather.rb +0 -27
  21. data/examples/dashed_elements.rb +0 -20
  22. data/examples/library.rb +0 -40
  23. data/examples/posts.rb +0 -27
  24. data/examples/rails.rb +0 -70
  25. data/examples/twitter.rb +0 -37
  26. data/examples/xml/active_record.xml +0 -70
  27. data/examples/xml/amazon.xml +0 -133
  28. data/examples/xml/current_weather.xml +0 -89
  29. data/examples/xml/dashed_elements.xml +0 -52
  30. data/examples/xml/posts.xml +0 -23
  31. data/examples/xml/twitter.xml +0 -422
  32. data/lib/representable/references.rb +0 -153
  33. data/spec/definition_spec.rb +0 -495
  34. data/spec/examples/active_record_spec.rb +0 -41
  35. data/spec/examples/amazon_spec.rb +0 -54
  36. data/spec/examples/current_weather_spec.rb +0 -37
  37. data/spec/examples/dashed_elements_spec.rb +0 -20
  38. data/spec/examples/library_spec.rb +0 -46
  39. data/spec/examples/post_spec.rb +0 -24
  40. data/spec/examples/twitter_spec.rb +0 -32
  41. data/spec/roxml_integration_test.rb +0 -289
  42. data/spec/roxml_spec.rb +0 -372
  43. data/spec/shared_specs.rb +0 -15
  44. data/spec/spec_helper.rb +0 -5
  45. data/spec/support/libxml.rb +0 -3
  46. data/spec/support/nokogiri.rb +0 -3
  47. data/spec/xml/array_spec.rb +0 -36
  48. data/spec/xml/attributes_spec.rb +0 -71
  49. data/spec/xml/encoding_spec.rb +0 -53
  50. data/spec/xml/namespace_spec.rb +0 -270
  51. data/spec/xml/namespaces_spec.rb +0 -67
  52. data/spec/xml/object_spec.rb +0 -82
  53. data/spec/xml/parser_spec.rb +0 -21
  54. data/spec/xml/text_spec.rb +0 -71
  55. data/test/fixtures/book_malformed.xml +0 -5
  56. data/test/fixtures/book_pair.xml +0 -8
  57. data/test/fixtures/book_text_with_attribute.xml +0 -5
  58. data/test/fixtures/book_valid.xml +0 -5
  59. data/test/fixtures/book_with_authors.xml +0 -7
  60. data/test/fixtures/book_with_contributions.xml +0 -9
  61. data/test/fixtures/book_with_contributors.xml +0 -7
  62. data/test/fixtures/book_with_contributors_attrs.xml +0 -7
  63. data/test/fixtures/book_with_default_namespace.xml +0 -9
  64. data/test/fixtures/book_with_depth.xml +0 -6
  65. data/test/fixtures/book_with_octal_pages.xml +0 -4
  66. data/test/fixtures/book_with_publisher.xml +0 -7
  67. data/test/fixtures/book_with_wrapped_attr.xml +0 -3
  68. data/test/fixtures/dictionary_of_attr_name_clashes.xml +0 -8
  69. data/test/fixtures/dictionary_of_attrs.xml +0 -6
  70. data/test/fixtures/dictionary_of_guarded_names.xml +0 -6
  71. data/test/fixtures/dictionary_of_mixeds.xml +0 -4
  72. data/test/fixtures/dictionary_of_name_clashes.xml +0 -10
  73. data/test/fixtures/dictionary_of_names.xml +0 -4
  74. data/test/fixtures/dictionary_of_texts.xml +0 -10
  75. data/test/fixtures/library.xml +0 -30
  76. data/test/fixtures/library_uppercase.xml +0 -30
  77. data/test/fixtures/muffins.xml +0 -3
  78. data/test/fixtures/nameless_ageless_youth.xml +0 -2
  79. data/test/fixtures/node_with_attr_name_conflicts.xml +0 -1
  80. data/test/fixtures/node_with_name_conflicts.xml +0 -4
  81. data/test/fixtures/numerology.xml +0 -4
  82. data/test/fixtures/person.xml +0 -1
  83. data/test/fixtures/person_with_guarded_mothers.xml +0 -13
  84. data/test/fixtures/person_with_mothers.xml +0 -10
  85. data/test/mocks/dictionaries.rb +0 -57
  86. data/test/mocks/mocks.rb +0 -279
  87. data/test/support/fixtures.rb +0 -11
  88. data/test/unit/definition_test.rb +0 -235
  89. data/test/unit/deprecations_test.rb +0 -24
  90. data/test/unit/to_xml_test.rb +0 -81
  91. data/test/unit/xml_attribute_test.rb +0 -39
  92. data/test/unit/xml_block_test.rb +0 -81
  93. data/test/unit/xml_bool_test.rb +0 -122
  94. data/test/unit/xml_convention_test.rb +0 -150
  95. data/test/unit/xml_hash_test.rb +0 -115
  96. data/test/unit/xml_initialize_test.rb +0 -49
  97. data/test/unit/xml_name_test.rb +0 -141
  98. data/test/unit/xml_namespace_test.rb +0 -31
  99. data/test/unit/xml_object_test.rb +0 -206
  100. data/test/unit/xml_required_test.rb +0 -94
  101. data/test/unit/xml_text_test.rb +0 -71
  102. data/website/index.html +0 -98
@@ -1,17 +1,17 @@
1
1
  require 'test_helper'
2
2
 
3
- class RoxmlTest < MiniTest::Spec
3
+ class RepresentableTest < MiniTest::Spec
4
4
  class Band
5
5
  include Representable
6
- xml_accessor :name
6
+ representable_property :name
7
7
  end
8
-
8
+
9
+ class PunkBand < Band
10
+ representable_property :street_cred
11
+ end
12
+
13
+
9
14
  describe "#representable_attrs" do
10
-
11
- class PunkBand < Band
12
- xml_accessor :street_cred
13
- end
14
-
15
15
  it "responds to #representable_attrs" do
16
16
  assert_equal 1, Band.representable_attrs.size
17
17
  assert_equal "name", Band.representable_attrs.first.name
@@ -24,6 +24,26 @@ class RoxmlTest < MiniTest::Spec
24
24
  end
25
25
  end
26
26
 
27
+ describe "#representable_property" do
28
+ it "creates accessors for the attribute" do
29
+ @band = PunkBand.new
30
+ assert @band.name = "Bad Religion"
31
+ assert_equal "Bad Religion", @band.name
32
+ end
33
+ end
34
+
35
+ describe "#representable_collection" do
36
+ class RockBand < Band
37
+ representable_collection :albums
38
+ end
39
+
40
+ it "creates correct Definition" do
41
+ assert_equal "albums", RockBand.representable_attrs.last.name
42
+ assert RockBand.representable_attrs.last.array?
43
+ end
44
+ end
45
+
46
+
27
47
  describe "#representation_name" do
28
48
  class SoundSystem
29
49
  include Representable
@@ -54,5 +74,4 @@ class RoxmlTest < MiniTest::Spec
54
74
  end
55
75
 
56
76
  end
57
-
58
77
  end
@@ -4,3 +4,5 @@ Bundler.setup
4
4
  require 'representable'
5
5
  require 'test/unit'
6
6
  require 'minitest/spec'
7
+ require 'test_xml/mini_test'
8
+
@@ -0,0 +1,192 @@
1
+ require 'test_helper'
2
+ require 'representable/xml'
3
+
4
+ class Band
5
+ include Representable::XML
6
+ representable_property :name
7
+
8
+ def initialize(name=nil)
9
+ name and self.name = name
10
+ end
11
+ end
12
+
13
+ class Label
14
+ def to_xml
15
+ "<label>Fat Wreck</label>"
16
+ end
17
+ end
18
+
19
+
20
+ class XmlTest < MiniTest::Spec
21
+ XML = Representable::XML
22
+ Def = Representable::Definition
23
+
24
+ describe "Xml module" do
25
+ class Band
26
+ include Representable::XML
27
+ representable_property :href, :from => "@href"
28
+ representable_property :title, :from => "@title"
29
+ end
30
+
31
+ it "#definition_class returns Definition class" do
32
+ assert_equal XML::Definition, Band.definition_class
33
+ end
34
+
35
+ describe "#binding_for_definition" do
36
+ it "returns AttributeBinding" do
37
+ assert_kind_of XML::AttributeBinding, XML.binding_for_definition(Def.new(:band, :from => "@band"))
38
+ end
39
+
40
+ it "returns ObjectBinding" do
41
+ assert_kind_of XML::ObjectBinding, XML.binding_for_definition(Def.new(:band, :as => Hash))
42
+ end
43
+
44
+ #it "returns NamespaceBinding" do
45
+ # assert_kind_of Xml::AttributeBinding, Xml.binding_for_definition(Def.new(:band, :from => "@band"))
46
+ #end
47
+
48
+ it "returns TextBinding" do
49
+ assert_kind_of XML::TextBinding, XML.binding_for_definition(Def.new(:band, :from => :content))
50
+ end
51
+ end
52
+ end
53
+ end
54
+
55
+ class AttributesTest < MiniTest::Spec
56
+ describe ":from => @rel" do
57
+ class Link
58
+ include Representable::XML
59
+ representable_property :href, :from => "@href"
60
+ representable_property :title, :from => "@title"
61
+ end
62
+
63
+ it "#from_xml creates correct accessors" do
64
+ link = Link.from_xml(%{
65
+ <a href="http://apotomo.de" title="Home, sweet home" />
66
+ })
67
+ assert_equal "http://apotomo.de", link.href
68
+ assert_equal "Home, sweet home", link.title
69
+ end
70
+
71
+ it "#to_xml serializes correctly" do
72
+ link = Link.new
73
+ link.href = "http://apotomo.de/"
74
+
75
+ assert_xml_equal %{<link href="http://apotomo.de/">}, link.to_xml.to_s
76
+ end
77
+ end
78
+ end
79
+
80
+ class TypedPropertyTest < MiniTest::Spec
81
+ describe ":as => Item" do
82
+ class Album
83
+ include Representable::XML
84
+ representable_property :band, :as => Band
85
+ representable_property :label, :as => Label
86
+ end
87
+
88
+ it "#from_xml creates one Item instance" do
89
+ album = Album.from_xml(%{
90
+ <album>
91
+ <band><name>Bad Religion</name></band>
92
+ </album>
93
+ })
94
+ assert_equal "Bad Religion", album.band.name
95
+ end
96
+
97
+ describe "#to_xml" do
98
+ it "doesn't escape xml from Band#to_xml" do
99
+ band = Band.new
100
+ band.name = "Bad Religion"
101
+ album = Album.new
102
+ album.band = band
103
+
104
+ assert_xml_equal %{<album>
105
+ <band>
106
+ <name>Bad Religion</name>
107
+ </band>
108
+ </album>}, album.to_xml.to_s
109
+ end
110
+
111
+ it "doesn't escape and wrap string from Label#to_xml" do
112
+ album = Album.new
113
+ album.label = Label.new
114
+
115
+ assert_xml_equal %{<album>
116
+ <label>Fat Wreck</label>
117
+ </album>}, album.to_xml.to_s
118
+ end
119
+ end
120
+ end
121
+ end
122
+
123
+
124
+ class CollectionTest < MiniTest::Spec
125
+ describe ":as => [Band], :tag => :band" do
126
+ class Compilation
127
+ include Representable::XML
128
+ representable_collection :bands, :as => Band, :tag => :band
129
+ end
130
+
131
+ describe "#representable_collection" do
132
+ it "declares a collection" do
133
+ assert Compilation.representable_attrs.first.array?
134
+ end
135
+
136
+ it "accepts :tag" do
137
+ assert_equal "band", Compilation.representable_attrs.first.name
138
+ end
139
+
140
+ end
141
+
142
+
143
+ describe "#from_xml" do
144
+ it "pushes collection items to array" do
145
+ cd = Compilation.from_xml(%{
146
+ <compilation>
147
+ <band><name>Diesel Boy</name></band>
148
+ <band><name>Cobra Skulls</name></band>
149
+ </compilation>
150
+ })
151
+ assert_equal ["Cobra Skulls", "Diesel Boy"], cd.bands.map(&:name).sort
152
+ end
153
+
154
+ it "collections can be empty" do
155
+ cd = Compilation.from_xml(%{
156
+ <compilation>
157
+ </compilation>
158
+ })
159
+ assert_equal [], cd.bands
160
+ end
161
+ end
162
+
163
+ it "responds to #to_xml" do
164
+ cd = Compilation.new
165
+ cd.bands = [Band.new("Diesel Boy"), Band.new("Bad Religion")]
166
+
167
+ assert_xml_equal %{<compilation>
168
+ <band><name>Diesel Boy</name></band>
169
+ <band><name>Bad Religion</name></band>
170
+ </compilation>}, cd.to_xml.to_s
171
+ end
172
+ end
173
+
174
+
175
+ describe ":as => []" do
176
+ class Album
177
+ include Representable::XML
178
+ representable_collection :songs, :tag => :song
179
+ end
180
+
181
+ it "collects untyped items" do
182
+ album = Album.from_xml(%{
183
+ <album>
184
+ <song>Two Kevins</song>
185
+ <song>Wright and Rong</song>
186
+ <song>Laundry Basket</song>
187
+ </album>
188
+ })
189
+ assert_equal ["Laundry Basket", "Two Kevins", "Wright and Rong"].sort, album.songs.sort
190
+ end
191
+ end
192
+ end
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: representable
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: true
4
+ prerelease: false
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
8
  - 1
9
- - alpha1
10
- version: 0.0.1.alpha1
9
+ version: 0.0.1
11
10
  platform: ruby
12
11
  authors:
13
12
  - Nick Sutterer
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2011-04-29 00:00:00 +02:00
17
+ date: 2011-05-09 00:00:00 +02:00
19
18
  default_executable:
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
@@ -24,13 +23,11 @@ dependencies:
24
23
  requirement: &id001 !ruby/object:Gem::Requirement
25
24
  none: false
26
25
  requirements:
27
- - - ~>
26
+ - - ">="
28
27
  - !ruby/object:Gem::Version
29
28
  segments:
30
- - 3
31
- - 0
32
29
  - 0
33
- version: 3.0.0
30
+ version: "0"
34
31
  type: :runtime
35
32
  version_requirements: *id001
36
33
  - !ruby/object:Gem::Dependency
@@ -73,7 +70,7 @@ dependencies:
73
70
  type: :runtime
74
71
  version_requirements: *id004
75
72
  - !ruby/object:Gem::Dependency
76
- name: rspec
73
+ name: json
77
74
  prerelease: false
78
75
  requirement: &id005 !ruby/object:Gem::Requirement
79
76
  none: false
@@ -83,10 +80,10 @@ dependencies:
83
80
  segments:
84
81
  - 0
85
82
  version: "0"
86
- type: :development
83
+ type: :runtime
87
84
  version_requirements: *id005
88
85
  - !ruby/object:Gem::Dependency
89
- name: test_xml
86
+ name: rspec
90
87
  prerelease: false
91
88
  requirement: &id006 !ruby/object:Gem::Requirement
92
89
  none: false
@@ -98,7 +95,20 @@ dependencies:
98
95
  version: "0"
99
96
  type: :development
100
97
  version_requirements: *id006
101
- description: CMaps representation documents from and to Ruby objects. Includes XML and JSON support, plain properties and compositions.
98
+ - !ruby/object:Gem::Dependency
99
+ name: test_xml
100
+ prerelease: false
101
+ requirement: &id007 !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ segments:
107
+ - 0
108
+ version: "0"
109
+ type: :development
110
+ version_requirements: *id007
111
+ description: Maps representation documents from and to Ruby objects. Includes XML and JSON support, plain properties and compositions.
102
112
  email:
103
113
  - apotonick@gmail.com
104
114
  executables: []
@@ -112,104 +122,23 @@ files:
112
122
  - .gitmodules
113
123
  - .rspec
114
124
  - Gemfile
115
- - History.txt
116
125
  - LICENSE
117
126
  - README.rdoc
118
127
  - Rakefile
119
- - TODO
120
- - VERSION
121
- - examples/amazon.rb
122
- - examples/current_weather.rb
123
- - examples/dashed_elements.rb
124
- - examples/library.rb
125
- - examples/posts.rb
126
- - examples/rails.rb
127
- - examples/twitter.rb
128
- - examples/xml/active_record.xml
129
- - examples/xml/amazon.xml
130
- - examples/xml/current_weather.xml
131
- - examples/xml/dashed_elements.xml
132
- - examples/xml/posts.xml
133
- - examples/xml/twitter.xml
134
128
  - lib/representable.rb
129
+ - lib/representable/bindings/json_bindings.rb
130
+ - lib/representable/bindings/xml_bindings.rb
135
131
  - lib/representable/definition.rb
132
+ - lib/representable/json.rb
136
133
  - lib/representable/nokogiri_extensions.rb
137
- - lib/representable/references.rb
138
134
  - lib/representable/version.rb
139
135
  - lib/representable/xml.rb
140
136
  - representable.gemspec
141
- - spec/definition_spec.rb
142
- - spec/examples/active_record_spec.rb
143
- - spec/examples/amazon_spec.rb
144
- - spec/examples/current_weather_spec.rb
145
- - spec/examples/dashed_elements_spec.rb
146
- - spec/examples/library_spec.rb
147
- - spec/examples/post_spec.rb
148
- - spec/examples/twitter_spec.rb
149
- - spec/roxml_integration_test.rb
150
- - spec/roxml_spec.rb
151
- - spec/shared_specs.rb
152
- - spec/spec_helper.rb
153
- - spec/support/libxml.rb
154
- - spec/support/nokogiri.rb
155
- - spec/xml/array_spec.rb
156
- - spec/xml/attributes_spec.rb
157
- - spec/xml/encoding_spec.rb
158
- - spec/xml/namespace_spec.rb
159
- - spec/xml/namespaces_spec.rb
160
- - spec/xml/object_spec.rb
161
- - spec/xml/parser_spec.rb
162
- - spec/xml/text_spec.rb
163
- - test/fixtures/book_malformed.xml
164
- - test/fixtures/book_pair.xml
165
- - test/fixtures/book_text_with_attribute.xml
166
- - test/fixtures/book_valid.xml
167
- - test/fixtures/book_with_authors.xml
168
- - test/fixtures/book_with_contributions.xml
169
- - test/fixtures/book_with_contributors.xml
170
- - test/fixtures/book_with_contributors_attrs.xml
171
- - test/fixtures/book_with_default_namespace.xml
172
- - test/fixtures/book_with_depth.xml
173
- - test/fixtures/book_with_octal_pages.xml
174
- - test/fixtures/book_with_publisher.xml
175
- - test/fixtures/book_with_wrapped_attr.xml
176
- - test/fixtures/dictionary_of_attr_name_clashes.xml
177
- - test/fixtures/dictionary_of_attrs.xml
178
- - test/fixtures/dictionary_of_guarded_names.xml
179
- - test/fixtures/dictionary_of_mixeds.xml
180
- - test/fixtures/dictionary_of_name_clashes.xml
181
- - test/fixtures/dictionary_of_names.xml
182
- - test/fixtures/dictionary_of_texts.xml
183
- - test/fixtures/library.xml
184
- - test/fixtures/library_uppercase.xml
185
- - test/fixtures/muffins.xml
186
- - test/fixtures/nameless_ageless_youth.xml
187
- - test/fixtures/node_with_attr_name_conflicts.xml
188
- - test/fixtures/node_with_name_conflicts.xml
189
- - test/fixtures/numerology.xml
190
- - test/fixtures/person.xml
191
- - test/fixtures/person_with_guarded_mothers.xml
192
- - test/fixtures/person_with_mothers.xml
193
- - test/mocks/dictionaries.rb
194
- - test/mocks/mocks.rb
195
- - test/roxml_test.rb
196
- - test/support/fixtures.rb
137
+ - test/bindings_test.rb
138
+ - test/json_test.rb
139
+ - test/representable_test.rb
197
140
  - test/test_helper.rb
198
- - test/unit/definition_test.rb
199
- - test/unit/deprecations_test.rb
200
- - test/unit/to_xml_test.rb
201
- - test/unit/xml_attribute_test.rb
202
- - test/unit/xml_block_test.rb
203
- - test/unit/xml_bool_test.rb
204
- - test/unit/xml_convention_test.rb
205
- - test/unit/xml_hash_test.rb
206
- - test/unit/xml_initialize_test.rb
207
- - test/unit/xml_name_test.rb
208
- - test/unit/xml_namespace_test.rb
209
- - test/unit/xml_object_test.rb
210
- - test/unit/xml_required_test.rb
211
- - test/unit/xml_text_test.rb
212
- - website/index.html
141
+ - test/xml_test.rb
213
142
  has_rdoc: true
214
143
  homepage: http://representable.apotomo.de
215
144
  licenses: []
@@ -230,13 +159,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
230
159
  required_rubygems_version: !ruby/object:Gem::Requirement
231
160
  none: false
232
161
  requirements:
233
- - - ">"
162
+ - - ">="
234
163
  - !ruby/object:Gem::Version
235
164
  segments:
236
- - 1
237
- - 3
238
- - 1
239
- version: 1.3.1
165
+ - 0
166
+ version: "0"
240
167
  requirements: []
241
168
 
242
169
  rubyforge_project: