oat 0.4.0 → 0.4.1

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 CHANGED
@@ -1,7 +1,7 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 89c8d41bf1fe016c6e714fc2cf8884de9b3b8af9
4
- data.tar.gz: 2022badfdfa88afe0677b21203efa51ba5e05eba
5
- SHA512:
6
- metadata.gz: c819633a5ad0726b9176ddd90abd7548a53b29a123ee078815e54f275484b1b2c36dd035e0beeef89ff152ccad4b0a912a94884c03527f3b192fc1437538992e
7
- data.tar.gz: a55145b6cecfd76f845e5ab7e952302545369d9bbeb7c558979f6ad7ac13397e94cd2ee39461be1278c5fa1c654729f5df1eba2d7d6d9d04df045e058656e535
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 893259bf479fe9a2252a4808283fb66b61a072c1
4
+ data.tar.gz: ff6de9dc5fdb82bdb5f8488bed683289921b65c7
5
+ SHA512:
6
+ metadata.gz: d9210ee288987100dddc96fe006c0285d0f28f225a70fb6f38119fa4c36ccc723e90fe603312e9be5df1bdde2161870e0df632d67c32e79e7e13af6458af3b61
7
+ data.tar.gz: 05d979883b19f1b84c7299c5bc3cf630f55e19ab336f3c77b33d059a1db51fdd29648a2c0f3981e632b4cc3a9215c29c2cf107176329013c8d63a9808e388217
data/README.md CHANGED
@@ -118,6 +118,12 @@ end
118
118
  Links to other resources can be added by using `link` with a name and an options hash. Most adapters expect just an href in the options hash, but some might support additional properties.
119
119
  Some adapters also suport passing `templated: true` in the options hash to indicate special treatment of a link template.
120
120
 
121
+
122
+ ### Adding meta-information
123
+
124
+ You can add meta-information about your JSON document via `meta :property, "value"`. When using the [JsonAPI](http://jsonapi.org/) adapter these properties are rendered in a [top level "meta" node](http://jsonapi.org/format/#document-top-level). When using the HAL or Siren adapters `meta` just acts as an alias to `property`, so the properties are rendered like normal properties.
125
+
126
+
121
127
  ## Adapters
122
128
 
123
129
  Using the included [HAL](http://stateless.co/hal_specification.html) adapter, the `ProductSerializer` above would render the following JSON:
@@ -14,6 +14,8 @@ module Oat
14
14
  data[key] = value
15
15
  end
16
16
 
17
+ alias_method :meta, :property
18
+
17
19
  def entity(name, obj, serializer_class = nil, context_options = {}, &block)
18
20
  entity_serializer = serializer_from_block_or_class(obj, serializer_class, context_options, &block)
19
21
  data[:_embedded][name] = entity_serializer ? entity_serializer.to_hash : nil
@@ -16,6 +16,7 @@ module Oat
16
16
  super
17
17
  @entities = {}
18
18
  @link_templates = {}
19
+ @meta = {}
19
20
  end
20
21
 
21
22
  def type(*types)
@@ -59,6 +60,10 @@ module Oat
59
60
  data[key] = value
60
61
  end
61
62
 
63
+ def meta(key, value)
64
+ @meta[key] = value
65
+ end
66
+
62
67
  def entity(name, obj, serializer_class = nil, context_options = {}, &block)
63
68
  ent = serializer_from_block_or_class(obj, serializer_class, context_options, &block)
64
69
  if ent
@@ -108,6 +113,7 @@ module Oat
108
113
  end
109
114
  h[:linked] = @entities if @entities.keys.any?
110
115
  h[:links] = @link_templates if @link_templates.keys.any?
116
+ h[:meta] = @meta if @meta.keys.any?
111
117
  return h
112
118
  end
113
119
  end
@@ -26,6 +26,8 @@ module Oat
26
26
  data[:properties][key] = value
27
27
  end
28
28
 
29
+ alias_method :meta, :property
30
+
29
31
  def entity(name, obj, serializer_class = nil, context_options = {}, &block)
30
32
  ent = serializer_from_block_or_class(obj, serializer_class, context_options, &block)
31
33
  data[:entities] << ent.to_hash if ent
@@ -36,6 +38,7 @@ module Oat
36
38
  entity name, obj, serializer_class, context_options, &block
37
39
  end
38
40
  end
41
+
39
42
  alias_method :collection, :entities
40
43
 
41
44
  def action(name, &block)
@@ -45,7 +45,6 @@ module Oat
45
45
  end
46
46
  end
47
47
 
48
-
49
48
  def respond_to_missing?(method_name, include_private = false)
50
49
  adapter.respond_to? method_name
51
50
  end
data/lib/oat/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Oat
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
@@ -16,7 +16,9 @@ describe Oat::Adapters::HAL do
16
16
  :name => user.name,
17
17
  :age => user.age,
18
18
  :controller_name => 'some_controller',
19
- :message_from_above => nil
19
+ :message_from_above => nil,
20
+ # Meta property
21
+ :nation => 'zulu'
20
22
  )
21
23
 
22
24
  # links
@@ -35,6 +35,28 @@ describe Oat::Adapters::JsonAPI do
35
35
  end
36
36
  end
37
37
 
38
+ context 'meta' do
39
+ subject(:meta) { hash.fetch(:meta) }
40
+
41
+ it 'contains meta properties' do
42
+ expect(meta[:nation]).to eq('zulu')
43
+ end
44
+
45
+ context 'without meta' do
46
+ let(:serializer_class) {
47
+ Class.new(Oat::Serializer) do
48
+ schema do
49
+ type 'users'
50
+ end
51
+ end
52
+ }
53
+
54
+ it 'does not contain meta information' do
55
+ expect(hash[:meta]).to be_nil
56
+ end
57
+ end
58
+ end
59
+
38
60
  context 'linked' do
39
61
  context 'using #entities' do
40
62
  subject(:linked_friends){ hash.fetch(:linked).fetch(:friends) }
@@ -17,7 +17,9 @@ describe Oat::Adapters::Siren do
17
17
  :name => user.name,
18
18
  :age => user.age,
19
19
  :controller_name => 'some_controller',
20
- :message_from_above => nil
20
+ :message_from_above => nil,
21
+ # Meta property
22
+ :nation => 'zulu'
21
23
  )
22
24
 
23
25
  expect(hash.fetch(:links).size).to be 2
@@ -57,7 +59,7 @@ describe Oat::Adapters::Siren do
57
59
 
58
60
  # action close_account
59
61
  actions = hash.fetch(:actions)
60
- expect(actions.size).to be 1
62
+ expect(actions.size).to eql(1)
61
63
  expect(actions.first).to include(
62
64
  :name => :close_account,
63
65
  :href => "http://foo.bar.com/#{user.id}/close_account",
data/spec/fixtures.rb CHANGED
@@ -14,6 +14,8 @@ module Fixtures
14
14
  link :self, :href => url_for(item.id)
15
15
  link :empty, :href => nil
16
16
 
17
+ meta :nation, 'zulu'
18
+
17
19
  property :id, item.id
18
20
  map_properties :name, :age
19
21
  properties do |attrs|
@@ -33,7 +35,7 @@ module Fixtures
33
35
  end
34
36
  end
35
37
 
36
- if respond_to?(:action)
38
+ if adapter.respond_to?(:action)
37
39
  action :close_account do |action|
38
40
  action.href "http://foo.bar.com/#{item.id}/close_account"
39
41
  action.class 'danger'
metadata CHANGED
@@ -1,63 +1,80 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: oat
3
- version: !ruby/object:Gem::Version
4
- version: 0.4.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.1
5
5
  platform: ruby
6
- authors:
6
+ authors:
7
7
  - Ismael Celis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
-
12
- date: 2014-04-07 00:00:00 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
11
+ date: 2014-04-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
15
14
  name: activesupport
16
- prerelease: false
17
- requirement: &id001 !ruby/object:Gem::Requirement
18
- requirements:
19
- - &id003
20
- - ">="
21
- - !ruby/object:Gem::Version
22
- version: "0"
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
23
20
  type: :runtime
24
- version_requirements: *id001
25
- - !ruby/object:Gem::Dependency
26
- name: bundler
27
21
  prerelease: false
28
- requirement: &id002 !ruby/object:Gem::Requirement
29
- requirements:
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
30
31
  - - ~>
31
- - !ruby/object:Gem::Version
32
- version: "1.3"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
33
34
  type: :development
34
- version_requirements: *id002
35
- - !ruby/object:Gem::Dependency
36
- name: rake
37
35
  prerelease: false
38
- requirement: &id004 !ruby/object:Gem::Requirement
39
- requirements:
40
- - *id003
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
41
48
  type: :development
42
- version_requirements: *id004
43
- - !ruby/object:Gem::Dependency
44
- name: rspec
45
49
  prerelease: false
46
- requirement: &id005 !ruby/object:Gem::Requirement
47
- requirements:
48
- - *id003
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
49
62
  type: :development
50
- version_requirements: *id005
51
- description: Oat helps you separate your API schema definitions from the underlying media type. Media types can be plugged or swapped on demand globally or on the content-negotiation phase
52
- email:
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Oat helps you separate your API schema definitions from the underlying
70
+ media type. Media types can be plugged or swapped on demand globally or on the content-negotiation
71
+ phase
72
+ email:
53
73
  - ismaelct@gmail.com
54
74
  executables: []
55
-
56
75
  extensions: []
57
-
58
76
  extra_rdoc_files: []
59
-
60
- files:
77
+ files:
61
78
  - .gitignore
62
79
  - .rspec
63
80
  - .travis.yml
@@ -89,33 +106,33 @@ files:
89
106
  - spec/serializer_spec.rb
90
107
  - spec/spec_helper.rb
91
108
  homepage: https://github.com/ismasan/oat
92
- licenses:
109
+ licenses:
93
110
  - MIT
94
111
  metadata: {}
95
-
96
112
  post_install_message:
97
113
  rdoc_options: []
98
-
99
- require_paths:
114
+ require_paths:
100
115
  - lib
101
- required_ruby_version: !ruby/object:Gem::Requirement
102
- requirements:
103
- - *id003
104
- required_rubygems_version: !ruby/object:Gem::Requirement
105
- requirements:
106
- - *id003
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
107
126
  requirements: []
108
-
109
127
  rubyforge_project:
110
- rubygems_version: 2.0.5
128
+ rubygems_version: 2.0.3
111
129
  signing_key:
112
130
  specification_version: 4
113
131
  summary: Adapters-based serializers with Hypermedia support
114
- test_files:
132
+ test_files:
115
133
  - spec/adapters/hal_spec.rb
116
134
  - spec/adapters/json_api_spec.rb
117
135
  - spec/adapters/siren_spec.rb
118
136
  - spec/fixtures.rb
119
137
  - spec/serializer_spec.rb
120
138
  - spec/spec_helper.rb
121
- has_rdoc: