oat 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/oat/adapters/json_api.rb +1 -1
- data/lib/oat/adapters/siren.rb +3 -3
- data/lib/oat/props.rb +6 -2
- data/lib/oat/serializer.rb +7 -0
- data/lib/oat/version.rb +1 -1
- data/spec/adapters/hal_spec.rb +1 -1
- data/spec/adapters/json_api_spec.rb +1 -1
- data/spec/adapters/siren_spec.rb +1 -1
- data/spec/fixtures.rb +3 -3
- data/spec/serializer_spec.rb +1 -1
- 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: bf0df88db08a4e8499e855c3297040d5a5624bb1
|
4
|
+
data.tar.gz: 52a898fa03b0a1e043da33169334a3c40ce981e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 76dc4f30fabc30a43962e608895c1036cc627923e95c0a4dda092b3e5a83c4e0f1b625d14975fd81b2df382d9615e9b8b302abeb8c040a6cbeca061acc0c677c
|
7
|
+
data.tar.gz: 7b9e468b4ca49e14b54d98d8342fa92254809600e0c93b22fece7ba88bf424c4bd61b36d07e9ea4c86bdb6d2cfd5f0f48fa3227b41c77c8bd1318deabe86aa78
|
data/lib/oat/adapters/siren.rb
CHANGED
@@ -15,7 +15,7 @@ module Oat
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def link(rel, opts = {})
|
18
|
-
data[:links] << {rel
|
18
|
+
data[:links] << {:rel => [rel]}.merge(opts)
|
19
19
|
end
|
20
20
|
|
21
21
|
def properties(&block)
|
@@ -48,7 +48,7 @@ module Oat
|
|
48
48
|
attr_reader :data
|
49
49
|
|
50
50
|
def initialize(name)
|
51
|
-
@data = { name
|
51
|
+
@data = { :name => name, :class => [], :fields => [] }
|
52
52
|
end
|
53
53
|
|
54
54
|
def class(value)
|
@@ -72,7 +72,7 @@ module Oat
|
|
72
72
|
attr_reader :data
|
73
73
|
|
74
74
|
def initialize(name)
|
75
|
-
@data = { name
|
75
|
+
@data = { :name => name }
|
76
76
|
end
|
77
77
|
|
78
78
|
%w(type value).each do |attribute|
|
data/lib/oat/props.rb
CHANGED
@@ -1,10 +1,14 @@
|
|
1
1
|
module Oat
|
2
|
-
class Props
|
2
|
+
class Props
|
3
3
|
|
4
4
|
def initialize
|
5
5
|
@attributes = {}
|
6
6
|
end
|
7
7
|
|
8
|
+
def id(value)
|
9
|
+
@attributes[:id] = value
|
10
|
+
end
|
11
|
+
|
8
12
|
def _from(data)
|
9
13
|
@attributes = data.to_hash
|
10
14
|
end
|
@@ -18,4 +22,4 @@ module Oat
|
|
18
22
|
end
|
19
23
|
|
20
24
|
end
|
21
|
-
end
|
25
|
+
end
|
data/lib/oat/serializer.rb
CHANGED
@@ -39,6 +39,13 @@ module Oat
|
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
+
def type(*args)
|
43
|
+
if adapter.respond_to?(:type) && adapter.method(:type).arity != 0
|
44
|
+
adapter.type(*args)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
|
42
49
|
def respond_to_missing?(method_name, include_private = false)
|
43
50
|
adapter.respond_to? method_name
|
44
51
|
end
|
data/lib/oat/version.rb
CHANGED
data/spec/adapters/hal_spec.rb
CHANGED
@@ -5,7 +5,7 @@ describe Oat::Adapters::HAL do
|
|
5
5
|
|
6
6
|
include Fixtures
|
7
7
|
|
8
|
-
subject{ serializer_class.new(user, {name
|
8
|
+
subject{ serializer_class.new(user, {:name => 'some_controller'}, Oat::Adapters::HAL) }
|
9
9
|
|
10
10
|
describe '#to_hash' do
|
11
11
|
it 'produces a HAL-compliant hash' do
|
@@ -5,7 +5,7 @@ describe Oat::Adapters::JsonAPI do
|
|
5
5
|
|
6
6
|
include Fixtures
|
7
7
|
|
8
|
-
subject{ serializer_class.new(user, {name
|
8
|
+
subject{ serializer_class.new(user, {:name => 'some_controller'}, Oat::Adapters::JsonAPI) }
|
9
9
|
|
10
10
|
describe '#to_hash' do
|
11
11
|
it 'produces a JSON-API compliant hash' do
|
data/spec/adapters/siren_spec.rb
CHANGED
@@ -5,7 +5,7 @@ describe Oat::Adapters::Siren do
|
|
5
5
|
|
6
6
|
include Fixtures
|
7
7
|
|
8
|
-
subject{ serializer_class.new(user, {name
|
8
|
+
subject{ serializer_class.new(user, {:name => 'some_controller'}, Oat::Adapters::Siren) }
|
9
9
|
|
10
10
|
describe '#to_hash' do
|
11
11
|
it 'produces a Siren-compliant hash' do
|
data/spec/fixtures.rb
CHANGED
@@ -11,8 +11,8 @@ module Fixtures
|
|
11
11
|
|
12
12
|
schema do
|
13
13
|
type 'user'
|
14
|
-
link :self, href
|
15
|
-
link :empty, href
|
14
|
+
link :self, :href => url_for(item.id)
|
15
|
+
link :empty, :href => nil
|
16
16
|
|
17
17
|
property :id, item.id
|
18
18
|
map_properties :name, :age
|
@@ -24,7 +24,7 @@ module Fixtures
|
|
24
24
|
|
25
25
|
entity :manager, item.manager do |manager, s|
|
26
26
|
s.type 'manager'
|
27
|
-
s.link :self, href
|
27
|
+
s.link :self, :href => url_for(manager.id)
|
28
28
|
s.properties do |attrs|
|
29
29
|
attrs.id manager.id
|
30
30
|
attrs.name manager.name
|
data/spec/serializer_spec.rb
CHANGED
@@ -54,7 +54,7 @@ describe Oat::Serializer do
|
|
54
54
|
|
55
55
|
describe '#to_hash' do
|
56
56
|
it 'builds Hash from item and context with attributes as defined in adapter' do
|
57
|
-
serializer = @sc.new(user1, name
|
57
|
+
serializer = @sc.new(user1, :name => 'some_controller')
|
58
58
|
serializer.to_hash.tap do |h|
|
59
59
|
h[:attributes][:special].should == 'Hello'
|
60
60
|
h[:attributes][:id].should == user1.id
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ismael Celis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-02-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|