roar 0.10.2 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,18 @@
1
+ ## 0.11.0
2
+
3
+ * Using representable-1.2.2 now. Be warned that in 1.2 parsing and rendering slightly changed. When a property is not found in the incoming document, it is ignored and thus might not be initialised in your represented model (empty collections are still set to an empty array). Also, the way `false` and `nil` values are rendered changed. Quoted from the representable CHANGES file:
4
+ * A property with false value will now be included in the rendered representation. Same applies to parsing, false values will now be included. That particularly means properties that used to be unset (i.e. nil) after parsing might be false now.
5
+ * You can include nil values now in your representations since #property respects :represent_nil => true.
6
+
7
+ * The `:except` option got deprecated in favor of `:exclude`.
8
+ * Hyperlinks can now have arbitrary attributes. To render, just provide `#link` with the options
9
+ <code>link :self, :title => "Mee!", "data-remote" => true</code>
10
+ When parsing, the options are avaible via `OpenStruct` compliant readers.
11
+ <code>link = Hyperlink.from_json({\"rel\":\"self\",\"data-url\":\"http://self\"} )
12
+ link.rel #=> "self"
13
+ link.send("data-url") #=> "http://self"
14
+ </code>
15
+
1
16
  ## 0.10.2
2
17
 
3
18
  * You can now pass values from outside to the render method (e.g. `#to_json`), they will be available as block parameters inside `#link`.
data/Gemfile CHANGED
@@ -3,7 +3,7 @@ source "http://rubygems.org"
3
3
  # Specify your gem's dependencies in roar.gemspec
4
4
  gemspec
5
5
 
6
- #gem "representable", :path => "../representable"
6
+ gem "representable", :path => "../representable"
7
7
 
8
8
 
9
9
  group :test do
@@ -129,20 +129,18 @@ module Roar
129
129
  end
130
130
 
131
131
 
132
- # An abstract hypermedia link with +rel+, +href+ and other attributes.
133
- # Overwrite the Hyperlink.params method if you need more link attributes.
134
- class Hyperlink
135
- def self.params
136
- [:rel, :href, :media, :title, :hreflang]
137
- end
132
+ require "ostruct"
133
+ # An abstract hypermedia link with arbitrary attributes.
134
+ class Hyperlink < OpenStruct
135
+ include Enumerable
138
136
 
139
- attr_accessor *params
137
+ def each(*args, &block)
138
+ marshal_dump.each(*args, &block)
139
+ end
140
140
 
141
- def initialize(options={})
142
- options.each do |k,v|
143
- next unless self.class.params.include?(k.to_sym)
144
- instance_variable_set("@#{k}", v)
145
- end
141
+ def replace(hash)
142
+ # #marshal_load requires symbol keys: http://apidock.com/ruby/v1_9_3_125/OpenStruct/marshal_load
143
+ marshal_load(hash.inject({}) { |h, (k,v)| h[k.to_sym] = v; h })
146
144
  end
147
145
  end
148
146
  end
@@ -49,13 +49,10 @@ module Roar
49
49
  end
50
50
  end
51
51
 
52
-
53
- # Represents a hyperlink in standard roar+json.
52
+ require "representable/json/hash"
53
+ # Represents a hyperlink in standard roar+json hash representation.
54
54
  module HyperlinkRepresenter
55
- include JSON
56
- Feature::Hypermedia::Hyperlink.params.each do |attr|
57
- property attr
58
- end
55
+ include Representable::JSON::Hash
59
56
  end
60
57
  end
61
58
  end
@@ -84,7 +84,7 @@ module Roar::Representer
84
84
  {}.tap do |hash|
85
85
  each do |link|
86
86
  # TODO: we statically use JSON::HyperlinkRepresenter here.
87
- hash[link.rel] = link.extend(JSON::HyperlinkRepresenter).to_hash(:except => [:rel])
87
+ hash[link.rel] = link.extend(JSON::HyperlinkRepresenter).to_hash(:exclude => [:rel])
88
88
  end
89
89
  end
90
90
  end
@@ -47,14 +47,12 @@ module Roar
47
47
  end
48
48
  end
49
49
 
50
+
51
+ require 'representable/xml/hash'
50
52
  module HyperlinkRepresenter
51
- include XML
53
+ include Representable::XML::AttributeHash
52
54
 
53
55
  self.representation_wrap = :link
54
-
55
- Feature::Hypermedia::Hyperlink.params.each do |attr|
56
- property attr, :attribute => true
57
- end
58
56
  end
59
57
  end
60
58
  end
@@ -1,3 +1,3 @@
1
1
  module Roar
2
- VERSION = "0.10.2"
2
+ VERSION = "0.11.0"
3
3
  end
@@ -1,3 +1,4 @@
1
+ require 'test_helper'
1
2
  require 'roar/representer/json/hal'
2
3
 
3
4
  class HalJsonTest < MiniTest::Spec
@@ -20,7 +21,7 @@ class HalJsonTest < MiniTest::Spec
20
21
  end
21
22
 
22
23
  it "renders links according to the HAL spec" do
23
- assert_equal "{\"links\":{\"self\":{\"href\":\"http://self\"},\"next\":{\"href\":\"http://hit\",\"title\":\"Hey, @myabc\"}}}", @song.to_json
24
+ assert_equal "{\"links\":{\"self\":{\"href\":\"http://self\"},\"next\":{\"title\":\"Hey, @myabc\",\"href\":\"http://hit\"}}}", @song.to_json
24
25
  end
25
26
 
26
27
  it "parses incoming JSON links correctly" do
@@ -29,7 +29,7 @@ class HypermediaTest
29
29
  end
30
30
  end
31
31
 
32
- assert_equal "{\"links\":[{\"rel\":\"self\",\"href\":\"http://self\",\"title\":\"Hey, @myabc\"}]}", Object.new.extend(@mod).to_json
32
+ assert_equal "{\"links\":[{\"rel\":\"self\",\"title\":\"Hey, @myabc\",\"href\":\"http://self\"}]}", Object.new.extend(@mod).to_json
33
33
  end
34
34
 
35
35
  it "receives options from to_*" do
@@ -234,15 +234,11 @@ class HyperlinkTest < MiniTest::Spec
234
234
  Hyperlink = Roar::Representer::Feature::Hypermedia::Hyperlink
235
235
  describe "Hyperlink" do
236
236
  before do
237
- @link = Hyperlink.new(:rel => "self", :href => "http://self")
237
+ @link = Hyperlink.new(:rel => "self", "href" => "http://self", "data-whatever" => "Hey, @myabc")
238
238
  end
239
239
 
240
240
  it "accepts string keys in constructor" do
241
- assert_equal "Hey, @myabc", Hyperlink.new("title" => "Hey, @myabc").title
242
- end
243
-
244
- it "responds to #media" do
245
- assert_equal nil, @link.media
241
+ assert_equal "Hey, @myabc", @link.send("data-whatever")
246
242
  end
247
243
 
248
244
  it "responds to #rel" do
@@ -252,6 +248,16 @@ class HyperlinkTest < MiniTest::Spec
252
248
  it "responds to #href" do
253
249
  assert_equal "http://self", @link.href
254
250
  end
251
+
252
+ it "responds to #replace with string keys" do
253
+ @link.replace("rel" => "next")
254
+ assert_equal nil, @link.href
255
+ assert_equal "next", @link.rel
256
+ end
257
+
258
+ it "responds to #each and implements Enumerable" do
259
+ assert_equal ["rel:self", "href:http://self", "data-whatever:Hey, @myabc"], @link.collect { |k,v| "#{k}:#{v}" }
260
+ end
255
261
  end
256
262
  end
257
263
 
@@ -31,8 +31,8 @@ class JsonRepresenterTest < MiniTest::Spec
31
31
  assert_equal '{"id":1}', @order.serialize
32
32
  end
33
33
 
34
- it "accepts :include and :except" do
35
- assert_equal '{}', @order.to_json(:except => [:id])
34
+ it "accepts :include and :exclude" do
35
+ assert_equal '{}', @order.to_json(:exclude => [:id])
36
36
  end
37
37
  end
38
38
 
@@ -55,8 +55,8 @@ class JsonRepresenterTest < MiniTest::Spec
55
55
  assert @order.from_json('')
56
56
  end
57
57
 
58
- it "accepts :include and :except" do
59
- @order.from_json('{"id":1}', :except => [:id])
58
+ it "accepts :include and :exclude" do
59
+ @order.from_json('{"id":1}', :exclude => [:id])
60
60
  assert_equal nil, @order.id
61
61
  end
62
62
  end
@@ -118,10 +118,11 @@ class JsonHypermediaTest
118
118
  end
119
119
 
120
120
  it "extracts links from JSON" do
121
- @r = @c.from_json({:links => [{:rel => "self", :href => "http://self"}]}.to_json)
121
+ r = @c.from_json({:links => [{:rel => "self", :href => "http://self"}]}.to_json)
122
122
 
123
- assert_equal 1, @r.links.size
124
- assert_equal(["self", "http://self"], [@r.links.first.rel, @r.links.first.href])
123
+ assert_equal 1, r.links.size
124
+ link = r.links.first
125
+ assert_equal(["self", "http://self"], [link.rel, link.href])
125
126
  end
126
127
 
127
128
  it "renders link: correctly in JSON" do
@@ -60,8 +60,8 @@ class XMLRepresenterFunctionalTest < MiniTest::Spec
60
60
  assert_equal @r.to_xml, @r.serialize
61
61
  end
62
62
 
63
- it "accepts :include and :except" do
64
- assert_equal '<order/>', @r.to_xml(:except => [:id])
63
+ it "accepts :include and :exclude" do
64
+ assert_equal '<order/>', @r.to_xml(:exclude => [:id])
65
65
  end
66
66
  end
67
67
 
@@ -76,8 +76,8 @@ class XMLRepresenterFunctionalTest < MiniTest::Spec
76
76
  assert_equal "1", @order.id
77
77
  end
78
78
 
79
- it "accepts :include and :except" do
80
- @order = Order.new.deserialize("<order><id>1</id></order>", :except => [:id])
79
+ it "accepts :include and :exclude" do
80
+ @order = Order.new.deserialize("<order><id>1</id></order>", :exclude => [:id])
81
81
  assert_equal nil, @order.id
82
82
  end
83
83
  end
@@ -95,8 +95,8 @@ class XMLRepresenterFunctionalTest < MiniTest::Spec
95
95
  assert_equal TestXmlRepresenter.from_xml("<order/>").id, TestXmlRepresenter.deserialize("<order/>").id
96
96
  end
97
97
 
98
- it "accepts :except option" do
99
- order = Order.from_xml(%{<order><id>1</id><pending>1</pending></order>}, :except => [:id])
98
+ it "accepts :exclude option" do
99
+ order = Order.from_xml(%{<order><id>1</id><pending>1</pending></order>}, :exclude => [:id])
100
100
  assert_equal nil, order.id
101
101
  assert_equal "1", order.pending
102
102
  end
metadata CHANGED
@@ -1,92 +1,88 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: roar
3
- version: !ruby/object:Gem::Version
4
- hash: 51
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.11.0
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 10
9
- - 2
10
- version: 0.10.2
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Nick Sutterer
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-05-18 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2012-06-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: representable
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 29
29
- segments:
30
- - 1
31
- - 1
32
- - 7
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
33
21
  version: 1.1.7
34
22
  type: :runtime
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
37
- name: rake
38
23
  prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
40
25
  none: false
41
- requirements:
42
- - - ">="
43
- - !ruby/object:Gem::Version
44
- hash: 3
45
- segments:
46
- - 0
47
- version: "0"
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 1.1.7
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
48
38
  type: :development
49
- version_requirements: *id002
50
- - !ruby/object:Gem::Dependency
51
- name: test_xml
52
39
  prerelease: false
53
- requirement: &id003 !ruby/object:Gem::Requirement
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: test_xml
48
+ requirement: !ruby/object:Gem::Requirement
54
49
  none: false
55
- requirements:
56
- - - ">="
57
- - !ruby/object:Gem::Version
58
- hash: 3
59
- segments:
60
- - 0
61
- version: "0"
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
62
54
  type: :development
63
- version_requirements: *id003
64
- - !ruby/object:Gem::Dependency
65
- name: minitest
66
55
  prerelease: false
67
- requirement: &id004 !ruby/object:Gem::Requirement
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: minitest
64
+ requirement: !ruby/object:Gem::Requirement
68
65
  none: false
69
- requirements:
70
- - - ">="
71
- - !ruby/object:Gem::Version
72
- hash: 45
73
- segments:
74
- - 2
75
- - 8
76
- - 1
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
77
69
  version: 2.8.1
78
70
  type: :development
79
- version_requirements: *id004
80
- description: Streamlines the development of RESTful, resource-oriented architectures in Ruby.
81
- email:
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: 2.8.1
78
+ description: Streamlines the development of RESTful, resource-oriented architectures
79
+ in Ruby.
80
+ email:
82
81
  - apotonick@gmail.com
83
82
  executables: []
84
-
85
83
  extensions: []
86
-
87
84
  extra_rdoc_files: []
88
-
89
- files:
85
+ files:
90
86
  - .gitignore
91
87
  - .travis.yml
92
88
  - CHANGES.markdown
@@ -162,36 +158,26 @@ files:
162
158
  - test/xml_representer_test.rb
163
159
  homepage: http://rubygems.org/gems/roar
164
160
  licenses: []
165
-
166
161
  post_install_message:
167
162
  rdoc_options: []
168
-
169
- require_paths:
163
+ require_paths:
170
164
  - lib
171
- required_ruby_version: !ruby/object:Gem::Requirement
165
+ required_ruby_version: !ruby/object:Gem::Requirement
172
166
  none: false
173
- requirements:
174
- - - ">="
175
- - !ruby/object:Gem::Version
176
- hash: 3
177
- segments:
178
- - 0
179
- version: "0"
180
- required_rubygems_version: !ruby/object:Gem::Requirement
167
+ requirements:
168
+ - - ! '>='
169
+ - !ruby/object:Gem::Version
170
+ version: '0'
171
+ required_rubygems_version: !ruby/object:Gem::Requirement
181
172
  none: false
182
- requirements:
183
- - - ">="
184
- - !ruby/object:Gem::Version
185
- hash: 3
186
- segments:
187
- - 0
188
- version: "0"
173
+ requirements:
174
+ - - ! '>='
175
+ - !ruby/object:Gem::Version
176
+ version: '0'
189
177
  requirements: []
190
-
191
178
  rubyforge_project: roar
192
- rubygems_version: 1.8.15
179
+ rubygems_version: 1.8.24
193
180
  signing_key:
194
181
  specification_version: 3
195
182
  summary: Resource-oriented architectures in Ruby.
196
183
  test_files: []
197
-