roar 1.0.2 → 1.0.3
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.
- checksums.yaml +4 -4
- data/.travis.yml +0 -2
- data/CHANGES.markdown +4 -0
- data/README.markdown +2 -6
- data/lib/roar/json/hal.rb +3 -2
- data/lib/roar/version.rb +1 -1
- data/test/hal_json_test.rb +15 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d5ead9158cbf50f06b53c2b3a965be1f055f2657
|
4
|
+
data.tar.gz: 7dede5c38e3e177de16473e463cb73c867597cb5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3991cfb442a827e6a6168b1791543ff0272bd4ab2255f617fc92c8a283f63175b95dc1d76fa06df1a90ee59904a28ee6637d0e54576d56994223aa4af838df34
|
7
|
+
data.tar.gz: b3822f0031b4f61d05d2d89359fc2291b6cc0fb1793a9073c3ebe385453894f50a378a83e9e73c93131d06e1832220335b7ce9bee9a8f480ce9def9919c52278
|
data/.travis.yml
CHANGED
data/CHANGES.markdown
CHANGED
data/README.markdown
CHANGED
@@ -3,6 +3,8 @@
|
|
3
3
|
_Resource-Oriented Architectures in Ruby._
|
4
4
|
|
5
5
|
[](https://travis-ci.org/apotonick/roar)
|
6
|
+
[](http://badge.fury.io/rb/roar)
|
7
|
+
[](https://gitter.im/trailblazer/chat)
|
6
8
|
|
7
9
|
## Introduction
|
8
10
|
|
@@ -14,12 +16,6 @@ Roar comes with built-in JSON, JSON-HAL, JSON-API and XML support. Its highly mo
|
|
14
16
|
|
15
17
|
Roar is completely framework-agnostic and loves being used in web kits like Rails, Webmachine, Sinatra, Padrino, etc. If you use Rails, consider [roar-rails](https://github.com/apotonick/roar-rails) for an enjoyable integration.
|
16
18
|
|
17
|
-
<a href="https://leanpub.com/trailblazer">
|
18
|
-

|
19
|
-
</a>
|
20
|
-
|
21
|
-
Roar is part of the [Trailblazer project](https://github.com/apotonick/trailblazer). Please [buy the book](https://leanpub.com/trailblazer) to support the development. Several chapters will be dedicated to Roar, its integration into operations, hypermedia formats and client-side usage.
|
22
|
-
|
23
19
|
## Representable
|
24
20
|
|
25
21
|
Roar is just a thin layer on top of the [representable](https://github.com/apotonick/representable) gem. While Roar gives you a DSL and behaviour for creating hypermedia APIs, representable implements all the mapping functionality.
|
data/lib/roar/json/hal.rb
CHANGED
@@ -56,8 +56,9 @@ module Roar
|
|
56
56
|
super.tap do |hash|
|
57
57
|
embedded = {}
|
58
58
|
representable_attrs.find_all do |dfn|
|
59
|
-
|
60
|
-
embedded
|
59
|
+
name = dfn[:as].(nil) # DISCUSS: should we simplify that in Representable?
|
60
|
+
next unless dfn[:embedded] and fragment = hash.delete(name)
|
61
|
+
embedded[name] = fragment
|
61
62
|
end
|
62
63
|
|
63
64
|
hash["_embedded"] = embedded if embedded.any?
|
data/lib/roar/version.rb
CHANGED
data/test/hal_json_test.rb
CHANGED
@@ -156,6 +156,21 @@ class JsonHalTest < MiniTest::Spec
|
|
156
156
|
it { Album.new(Artist.new("Bare, Jr."), [Song.new("Tobacco Spit")]).extend(representer).to_hash.must_equal({"_embedded"=>{"artist"=>{"name"=>"Bare, Jr."}, "songs"=>[{"title"=>"Tobacco Spit"}]}}) }
|
157
157
|
it { Album.new.extend(representer).to_hash.must_equal({}) }
|
158
158
|
end
|
159
|
+
|
160
|
+
describe "as: alias" do
|
161
|
+
representer! do
|
162
|
+
property :artist, as: :my_artist, class: Artist, embedded: true do
|
163
|
+
property :name
|
164
|
+
end
|
165
|
+
|
166
|
+
collection :songs, as: :my_songs, class: Song, embedded: true do
|
167
|
+
property :title
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
it { Album.new(Artist.new("Bare, Jr."), [Song.new("Tobacco Spit")]).extend(representer).to_hash.must_equal({"_embedded"=>{"my_artist"=>{"name"=>"Bare, Jr."}, "my_songs"=>[{"title"=>"Tobacco Spit"}]}}) }
|
172
|
+
it { Album.new.extend(representer).from_hash({"_embedded"=>{"my_artist"=>{"name"=>"Bare, Jr."}, "my_songs"=>[{"title"=>"Tobacco Spit"}]}}).inspect.must_equal "#<struct JsonHalTest::Album artist=#<struct JsonHalTest::Artist name=\"Bare, Jr.\">, songs=[#<struct JsonHalTest::Song title=\"Tobacco Spit\">]>" }
|
173
|
+
end
|
159
174
|
end
|
160
175
|
|
161
176
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: roar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Sutterer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-09-
|
11
|
+
date: 2015-09-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: representable
|