oat 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6b724a91b70428b2d8119bb6bdd9a30c814ac10d
4
- data.tar.gz: 043edf3fd0dcb99075cf01660851e8a183270d1f
3
+ metadata.gz: 557a927aa61099a4c1e3eb84c7cb4520247cb8ff
4
+ data.tar.gz: ba7fd708868211a749732afd0d8e48b2f3fde252
5
5
  SHA512:
6
- metadata.gz: 7662b374492e8c20c8e3fbe030d1b08bbcd27665cb4230a4c696142b1e80d6d298eb4870977943ac99d12d20517792c97240d88602b28f29c2bd0974f3bf7455
7
- data.tar.gz: a4887962d0788adfcb7992a79e21c884ddb92734c690b99f77c9541278003db4c7fbe5c5f1ffae2696c114c58a7236ce621a619ac9c44b3c8d151b4eafee6b47
6
+ metadata.gz: e6ada6ca09572536681a11853b3958e676893cce4508f35006c33ad56e11ea4eb5f35e4bf3f436156be98b800af92efd935dae252cd4b89fcb9e5a4333a48134
7
+ data.tar.gz: 7bb01a60f853efd5fe8b7a7457565fe7bd41e8716ba6c80841abc9195442034d5ed1b6610a34d295da73b37391beaff0072fc7fc295eaaea81e595057de797b9
data/.travis.yml CHANGED
@@ -23,8 +23,3 @@ matrix:
23
23
  rvm: 1.8.7
24
24
  - gemfile: gemfiles/Gemfile.as-4.0.x
25
25
  rvm: 1.9.2
26
- allow_failures:
27
- - gemfile: gemfiles/Gemfile.as-3.0.x
28
- rvm: 1.8.7
29
- - gemfile: gemfiles/Gemfile.as-1.4.4
30
- rvm: 1.8.7
data/README.md CHANGED
@@ -1,4 +1,6 @@
1
- # Oat [![Build Status](https://travis-ci.org/ismasan/oat.png)](https://travis-ci.org/ismasan/oat)
1
+ # Oat
2
+ [![Build Status](https://travis-ci.org/ismasan/oat.png)](https://travis-ci.org/ismasan/oat)
3
+ [![Gem Version](https://badge.fury.io/rb/oat.png)](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 = entity_without_root(obj, serializer_class, context_options, &block)
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 = entity_without_root(obj, serializer_class, context_options, &block)
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
- h = {root_name.pluralize.to_sym => [data]}
61
- h[:linked] = @entities if @entities.keys.any?
62
- h
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
@@ -1,3 +1,3 @@
1
1
  module Oat
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ismael Celis