oat 0.2.2 → 0.2.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 -5
- data/README.md +3 -1
- data/lib/oat/adapter.rb +1 -1
- data/lib/oat/adapters/json_api.rb +9 -10
- data/lib/oat/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 557a927aa61099a4c1e3eb84c7cb4520247cb8ff
|
4
|
+
data.tar.gz: ba7fd708868211a749732afd0d8e48b2f3fde252
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e6ada6ca09572536681a11853b3958e676893cce4508f35006c33ad56e11ea4eb5f35e4bf3f436156be98b800af92efd935dae252cd4b89fcb9e5a4333a48134
|
7
|
+
data.tar.gz: 7bb01a60f853efd5fe8b7a7457565fe7bd41e8716ba6c80841abc9195442034d5ed1b6610a34d295da73b37391beaff0072fc7fc295eaaea81e595057de797b9
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
# Oat
|
1
|
+
# Oat
|
2
|
+
[](https://travis-ci.org/ismasan/oat)
|
3
|
+
[](http://badge.fury.io/rb/oat)
|
2
4
|
|
3
5
|
Adapters-based API serializers with Hypermedia support for Ruby apps. Read [the blog post](http://new-bamboo.co.uk/blog/2013/11/21/oat-explicit-media-type-serializers-in-ruby) for context and motivation.
|
4
6
|
|
data/lib/oat/adapter.rb
CHANGED
@@ -31,7 +31,7 @@ module Oat
|
|
31
31
|
serializer.top.instance_exec(obj, s, &block)
|
32
32
|
s.to_hash
|
33
33
|
else
|
34
|
-
serializer_class.new(obj, serializer.context.merge(context_options), serializer.adapter_class).to_hash
|
34
|
+
serializer_class.new(obj, serializer.context.merge(context_options), serializer.adapter_class, serializer.top).to_hash
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
@@ -34,7 +34,7 @@ module Oat
|
|
34
34
|
|
35
35
|
def entity(name, obj, serializer_class = nil, context_options = {}, &block)
|
36
36
|
@entities[name.to_s.pluralize.to_sym] ||= []
|
37
|
-
ent =
|
37
|
+
ent = serializer_from_block_or_class(obj, serializer_class, context_options, &block)
|
38
38
|
if ent
|
39
39
|
link name, :href => ent[:id]
|
40
40
|
@entities[name.to_s.pluralize.to_sym] << ent
|
@@ -47,7 +47,7 @@ module Oat
|
|
47
47
|
|
48
48
|
collection.each do |obj|
|
49
49
|
@entities[link_name] ||= []
|
50
|
-
ent =
|
50
|
+
ent = serializer_from_block_or_class(obj, serializer_class, context_options, &block)
|
51
51
|
if ent
|
52
52
|
data[:links][link_name] << ent[:id]
|
53
53
|
@entities[link_name] << ent
|
@@ -57,20 +57,19 @@ module Oat
|
|
57
57
|
|
58
58
|
def to_hash
|
59
59
|
raise "JSON API entities MUST define a type. Use type 'user' in your serializers" unless root_name
|
60
|
-
|
61
|
-
|
62
|
-
|
60
|
+
if serializer.top != serializer
|
61
|
+
return data
|
62
|
+
else
|
63
|
+
h = {root_name.pluralize.to_sym => [data]}
|
64
|
+
h[:linked] = @entities if @entities.keys.any?
|
65
|
+
return h
|
66
|
+
end
|
63
67
|
end
|
64
68
|
|
65
69
|
protected
|
66
70
|
|
67
71
|
attr_reader :root_name
|
68
72
|
|
69
|
-
def entity_without_root(obj, serializer_class = nil, context_options = {}, &block)
|
70
|
-
ent = serializer_from_block_or_class(obj, serializer_class, context_options, &block)
|
71
|
-
ent.values.first.first if ent
|
72
|
-
end
|
73
|
-
|
74
73
|
end
|
75
74
|
end
|
76
75
|
end
|
data/lib/oat/version.rb
CHANGED