jsonapi-deserializable 0.1.1.beta3 → 0.1.1

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: f3004871b4ea0f17caaeab2c1f000c632337c486
4
- data.tar.gz: 4eb06414674e45c45fc3d276ffa966bc97313ae7
3
+ metadata.gz: '00948aee890ce50979d9e79091d3d773c718c81d'
4
+ data.tar.gz: be1b26548249485868b080a05d232119ac5c7f71
5
5
  SHA512:
6
- metadata.gz: fdf14b9d40b30ea331a01b10212be3b5582785e45634ab7e49e2d81957a4408af6ce838d05dc27e9d86828a704cef1a2eb23e5331d2c13d4fa131829c6a4c03e
7
- data.tar.gz: ee5342f0d5444e68773e504353000090dc71117fba3eee3a0af21399c32836085eab9f8076dd70a2cfe54385a85f9140c692007199f12b70ef60315ca76cad64
6
+ metadata.gz: 1f74445bc44fef0931df10075cf8cdd359c91c8c178c4ba2a59318168094f18b9ca5ca30f131f3a6d401497d41c33cd3c628f79069294dae41cc168f5de2bfa6
7
+ data.tar.gz: a2bff5fd5dd4442935088c08208f400d0c79fc08363c2b8742df0d70f33f979883b051bacc460d1b3ba2cf9c5d31e622c399cd2bf34051f8dd04bfa1fee129d4
data/README.md CHANGED
@@ -5,100 +5,14 @@ hashes.
5
5
  ## Status
6
6
 
7
7
  [![Gem Version](https://badge.fury.io/rb/jsonapi-deserializable.svg)](https://badge.fury.io/rb/jsonapi-deserializable)
8
- [![Build Status](https://secure.travis-ci.org/beauby/jsonapi-deserializable.svg?branch=master)](http://travis-ci.org/beauby/jsonapi-deserializable?branch=master)
8
+ [![Build Status](https://secure.travis-ci.org/jsonapi-rb/jsonapi-deserializable.svg?branch=master)](http://travis-ci.org/jsonapi-rb/deserializable?branch=master)
9
+ [![codecov](https://codecov.io/gh/jsonapi-rb/jsonapi-deserializable/branch/master/graph/badge.svg)](https://codecov.io/gh/jsonapi-rb/deserializable)
10
+ [![Gitter chat](https://badges.gitter.im/gitterHQ/gitter.png)](https://gitter.im/jsonapi-rb/Lobby)
9
11
 
10
- ## Installation
11
- ```ruby
12
- # In Gemfile
13
- gem 'jsonapi-deserializable'
14
- ```
15
- then
16
- ```
17
- $ bundle
18
- ```
19
- or manually via
20
- ```
21
- $ gem install jsonapi-deserializable
22
- ```
23
12
 
24
- ## Usage
13
+ ## Usage and documentation
25
14
 
26
- First, require the gem:
27
- ```ruby
28
- require 'jsonapi/deserializable'
29
- ```
30
-
31
- Then, define some resource/relationship classes:
32
-
33
- ### Resources
34
-
35
- ```ruby
36
- class DeserializableCreatePost < JSONAPI::Deserializable::Resource
37
- type
38
- attribute :title
39
- attribute :date { |date| field date: DateTime.parse(date) }
40
- has_one :author do |rel, id, type|
41
- field author_id: id
42
- field author_type: type
43
- end
44
- has_many :comments do |rel, ids, types|
45
- field comment_ids: ids
46
- field comment_types: types.map do |type|
47
- camelize(singularize(type))
48
- end
49
- end
50
- end
51
- ```
52
- Finally, build your hash from the deserializable resource:
53
- ```ruby
54
- payload = {
55
- 'data' => {
56
- 'id' => '1',
57
- 'type' => 'posts',
58
- 'attributes' => {
59
- 'title' => 'Title',
60
- 'date' => '2016-01-10 02:30:00'
61
- },
62
- 'relationships' => {
63
- 'author' => {
64
- 'data' => { 'type' => 'users', 'id' => '1337' }
65
- },
66
- 'comments' => {
67
- 'data' => [
68
- { 'type' => 'comments', 'id' => '123' },
69
- { 'type' => 'comments', 'id' => '234' },
70
- { 'type' => 'comments', 'id' => '345' }
71
- ]
72
- }
73
- }
74
- }
75
- }
76
-
77
- DeserializableCreateUser.(payload)
78
- # => {
79
- # id: '1',
80
- # title: 'Title',
81
- # date: #<DateTime: 2016-01-10T02:30:00+00:00 ((2457398j,9000s,0n),+0s,2299161j)>,
82
- # author_id: '1337',
83
- # author_type: 'users',
84
- # comment_ids: ['123', '234', '345']
85
- # comment_types: ['Comment', 'Comment', 'Comment']
86
- # }
87
- ```
88
-
89
- ### Relationships
90
-
91
- ```
92
- class DeserializablePostComments < JSONAPI::Deserializable::Relationship
93
- has_many do |rel, ids, types|
94
- field comment_ids: ids
95
- field comment_types: types.map do |ri|
96
- camelize(singularize(type))
97
- end
98
- field comments_meta: rel['meta']
99
- end
100
- end
101
- ```
15
+ See [jsonapi-rb.org/guides/deserialization](http://jsonapi-rb.org/guides/deserialization).
102
16
 
103
17
  ## License
104
18
 
@@ -1,15 +1,17 @@
1
- require 'jsonapi/deserializable/relationship_dsl'
1
+ require 'jsonapi/deserializable/relationship/dsl'
2
+ require 'jsonapi/parser/relationship'
2
3
 
3
4
  module JSONAPI
4
5
  module Deserializable
5
6
  class Relationship
6
- include RelationshipDSL
7
+ extend DSL
7
8
 
8
9
  class << self
9
10
  attr_accessor :has_one_block, :has_many_block
10
11
  end
11
12
 
12
13
  def self.inherited(klass)
14
+ super
13
15
  klass.has_one_block = has_one_block
14
16
  klass.has_many_block = has_many_block
15
17
  end
@@ -19,32 +21,47 @@ module JSONAPI
19
21
  end
20
22
 
21
23
  def initialize(payload)
24
+ Parser::Relationship.parse!(payload)
22
25
  @document = payload
23
26
  @data = payload['data']
24
27
  deserialize!
28
+ freeze
25
29
  end
26
30
 
27
- def to_h
31
+ def to_hash
28
32
  @hash
29
33
  end
34
+ alias to_h to_hash
30
35
 
31
36
  private
32
37
 
33
38
  def deserialize!
34
- @hash = {}
35
- if @data.is_a?(Array)
36
- ids = @data.map { |ri| ri['id'] }
37
- types = @data.map { |ri| ri['type'] }
38
- instance_exec(@document, ids, types, &self.class.has_many_block)
39
+ @hash =
40
+ if @data.is_a?(Array)
41
+ deserialize_has_many
42
+ elsif @data.nil? || @data.is_a?(Hash)
43
+ deserialize_has_one
44
+ end
45
+ end
46
+
47
+ def deserialize_has_one
48
+ id = @data && @data['id']
49
+ type = @data && @data['type']
50
+ if self.class.has_one_block
51
+ self.class.has_one_block.call(@document, id, type)
39
52
  else
40
- id = @data && @data['id']
41
- type = @data && @data['type']
42
- instance_exec(@document, id, type, &self.class.has_one_block)
53
+ { id: id, type: type }
43
54
  end
44
55
  end
45
56
 
46
- def field(hash)
47
- @hash.merge!(hash)
57
+ def deserialize_has_many
58
+ ids = @data.map { |ri| ri['id'] }
59
+ types = @data.map { |ri| ri['type'] }
60
+ if self.class.has_many_block
61
+ self.class.has_many_block.call(@document, ids, types)
62
+ else
63
+ { ids: ids, types: types }
64
+ end
48
65
  end
49
66
  end
50
67
  end
@@ -0,0 +1,15 @@
1
+ module JSONAPI
2
+ module Deserializable
3
+ class Relationship
4
+ module DSL
5
+ def has_one(&block)
6
+ self.has_one_block = block
7
+ end
8
+
9
+ def has_many(&block)
10
+ self.has_many_block = block
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,34 +1,49 @@
1
- require 'jsonapi/deserializable/resource_dsl'
1
+ require 'jsonapi/deserializable/resource/configuration'
2
+ require 'jsonapi/deserializable/resource/dsl'
3
+ require 'jsonapi/parser/resource'
2
4
 
3
5
  module JSONAPI
4
6
  module Deserializable
5
7
  class Resource
6
- include ResourceDSL
8
+ extend DSL
7
9
 
8
10
  class << self
9
- attr_accessor :type_block, :id_block
10
- attr_accessor :attr_blocks
11
- attr_accessor :has_one_rel_blocks, :has_many_rel_blocks
11
+ attr_accessor :type_block, :id_block, :attr_blocks,
12
+ :has_one_rel_blocks, :has_many_rel_blocks,
13
+ :configuration
12
14
  end
13
15
 
14
- self.attr_blocks = {}
15
- self.has_one_rel_blocks = {}
16
+ @class_cache = {}
17
+
18
+ self.configuration = Configuration.new
19
+ self.attr_blocks = {}
20
+ self.has_one_rel_blocks = {}
16
21
  self.has_many_rel_blocks = {}
17
22
 
18
23
  def self.inherited(klass)
19
24
  super
20
- klass.type_block = type_block
21
- klass.id_block = id_block
22
- klass.attr_blocks = attr_blocks.dup
25
+ klass.configuration = configuration.dup
26
+ klass.type_block = type_block
27
+ klass.id_block = id_block
28
+ klass.attr_blocks = attr_blocks.dup
23
29
  klass.has_one_rel_blocks = has_one_rel_blocks.dup
24
30
  klass.has_many_rel_blocks = has_many_rel_blocks.dup
25
31
  end
26
32
 
33
+ def self.configure
34
+ yield(configuration)
35
+ end
36
+
37
+ def self.[](name)
38
+ @class_cache[name] ||= Class.new(self)
39
+ end
40
+
27
41
  def self.call(payload)
28
42
  new(payload).to_h
29
43
  end
30
44
 
31
45
  def initialize(payload)
46
+ Parser::Resource.parse!(payload)
32
47
  @document = payload
33
48
  @data = @document['data']
34
49
  @type = @data['type']
@@ -36,75 +51,105 @@ module JSONAPI
36
51
  @attributes = @data['attributes'] || {}
37
52
  @relationships = @data['relationships'] || {}
38
53
  deserialize!
54
+ freeze
39
55
  end
40
56
 
41
- def to_h
57
+ def to_hash
42
58
  @hash
43
59
  end
60
+ alias to_h to_hash
61
+
62
+ attr_reader :reverse_mapping
44
63
 
45
64
  private
46
65
 
47
- def deserialize!
48
- @hash = {}
49
- deserialize_type!
50
- deserialize_id!
51
- deserialize_attrs!
52
- deserialize_rels!
66
+ def configuration
67
+ self.class.configuration
53
68
  end
54
69
 
55
- def deserialize_type!
56
- return unless @type && self.class.type_block
57
- instance_exec(@type, &self.class.type_block)
70
+ def register_mappings(keys, path)
71
+ keys.each do |k|
72
+ @reverse_mapping[k] = path
73
+ end
58
74
  end
59
75
 
60
- def deserialize_id!
61
- return unless @id && self.class.id_block
62
- instance_exec(@id, &self.class.id_block)
76
+ def deserialize!
77
+ @reverse_mapping = {}
78
+ hashes = [deserialize_type, deserialize_id,
79
+ deserialize_attrs, deserialize_rels]
80
+ @hash = hashes.reduce({}, :merge)
63
81
  end
64
82
 
65
- def deserialize_attrs!
66
- self.class.attr_blocks.each do |attr, block|
67
- next unless @attributes.key?(attr)
68
- instance_exec(@attributes[attr], &block)
69
- end
83
+ def deserialize_type
84
+ block = self.class.type_block || configuration.default_type
85
+ hash = block.call(@type)
86
+ register_mappings(hash.keys, '/data/type')
87
+ hash
70
88
  end
71
89
 
72
- def deserialize_rels!
73
- deserialize_has_one_rels!
74
- deserialize_has_many_rels!
90
+ def deserialize_id
91
+ return {} unless @id
92
+ block = self.class.id_block || configuration.default_id
93
+ hash = block.call(@id)
94
+ register_mappings(hash.keys, '/data/id')
95
+ hash
75
96
  end
76
97
 
77
- def deserialize_has_one_rels!
78
- self.class.has_one_rel_blocks.each do |key, block|
79
- rel = @relationships[key]
80
- next unless rel && (rel['data'].nil? || rel['data'].is_a?(Hash))
81
- deserialize_has_one_rel!(rel, &block)
82
- end
98
+ def deserialize_attrs
99
+ @attributes
100
+ .map { |key, val| deserialize_attr(key, val) }
101
+ .reduce({}, :merge)
83
102
  end
84
103
 
85
- def deserialize_has_one_rel!(rel, &block)
86
- id = rel['data'] && rel['data']['id']
87
- type = rel['data'] && rel['data']['type']
88
- instance_exec(rel, id, type, &block)
104
+ def deserialize_attr(key, val)
105
+ hash = if self.class.attr_blocks.key?(key)
106
+ self.class.attr_blocks[key].call(val)
107
+ else
108
+ configuration.default_attribute.call(key, val)
109
+ end
110
+ register_mappings(hash.keys, "/data/attributes/#{key}")
111
+ hash
89
112
  end
90
113
 
91
- def deserialize_has_many_rels!
92
- self.class.has_many_rel_blocks.each do |key, block|
93
- rel = @relationships[key]
94
- next unless rel && rel['data'].is_a?(Array)
95
- deserialize_has_many_rel!(rel, &block)
96
- end
114
+ def deserialize_rels
115
+ @relationships
116
+ .map { |key, val| deserialize_rel(key, val) }
117
+ .reduce({}, :merge)
97
118
  end
98
119
 
99
- def deserialize_has_many_rel!(rel, &block)
100
- ids = rel['data'].map { |ri| ri['id'] }
101
- types = rel['data'].map { |ri| ri['type'] }
102
- instance_exec(rel, ids, types, &block)
120
+ def deserialize_rel(key, val)
121
+ hash = if val['data'].is_a?(Array)
122
+ deserialize_has_many_rel(key, val)
123
+ else
124
+ deserialize_has_one_rel(key, val)
125
+ end
126
+ register_mappings(hash.keys, "/data/relationships/#{key}")
127
+ hash
103
128
  end
104
129
 
105
- def field(hash)
106
- @hash.merge!(hash)
130
+ # rubocop: disable Metrics/AbcSize
131
+ def deserialize_has_one_rel(key, val)
132
+ id = val['data'] && val['data']['id']
133
+ type = val['data'] && val['data']['type']
134
+ if self.class.has_one_rel_blocks.key?(key)
135
+ self.class.has_one_rel_blocks[key].call(val, id, type)
136
+ else
137
+ configuration.default_has_one.call(key, val, id, type)
138
+ end
139
+ end
140
+ # rubocop: enable Metrics/AbcSize
141
+
142
+ # rubocop: disable Metrics/AbcSize
143
+ def deserialize_has_many_rel(key, val)
144
+ ids = val['data'].map { |ri| ri['id'] }
145
+ types = val['data'].map { |ri| ri['type'] }
146
+ if self.class.has_many_rel_blocks.key?(key)
147
+ self.class.has_many_rel_blocks[key].call(val, ids, types)
148
+ else
149
+ configuration.default_has_many.call(key, val, ids, types)
150
+ end
107
151
  end
152
+ # rubocop: enable Metrics/AbcSize
108
153
  end
109
154
  end
110
155
  end
@@ -0,0 +1,17 @@
1
+ require 'jsonapi/deserializable/resource/configuration'
2
+
3
+ module JSONAPI
4
+ module Deserializable
5
+ module Configurable
6
+ def self.included(klass)
7
+ klass.class_eval do
8
+ extend ClassMethods
9
+ include InstanceMethods
10
+ end
11
+ end
12
+ module ClassMethods
13
+
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,28 @@
1
+ module JSONAPI
2
+ module Deserializable
3
+ class Resource
4
+ class Configuration
5
+ DEFAULT_TYPE_BLOCK = proc { |t| { type: t } }
6
+ DEFAULT_ID_BLOCK = proc { |i| { id: i } }
7
+ DEFAULT_ATTR_BLOCK = proc { |k, v| { k.to_sym => v } }
8
+ DEFAULT_HAS_ONE_BLOCK = proc do |k, _, i, t|
9
+ { "#{k}_id".to_sym => i, "#{k}_type".to_sym => t }
10
+ end
11
+ DEFAULT_HAS_MANY_BLOCK = proc do |k, _, i, t|
12
+ { "#{k}_ids".to_sym => i, "#{k}_types".to_sym => t }
13
+ end
14
+
15
+ attr_accessor :default_type, :default_id, :default_attribute,
16
+ :default_has_one, :default_has_many
17
+
18
+ def initialize
19
+ self.default_type = DEFAULT_TYPE_BLOCK
20
+ self.default_id = DEFAULT_ID_BLOCK
21
+ self.default_attribute = DEFAULT_ATTR_BLOCK
22
+ self.default_has_one = DEFAULT_HAS_ONE_BLOCK
23
+ self.default_has_many = DEFAULT_HAS_MANY_BLOCK
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -1,76 +1,26 @@
1
1
  module JSONAPI
2
2
  module Deserializable
3
- module ResourceDSL
4
- attr_accessor :field_blocks, :validations
5
-
6
- def required(&block)
7
- add_validations!(FieldList.new(:required, &block).to_h)
8
- end
9
-
10
- def optional(&block)
11
- add_validations!(FieldList.new(:optional, &block).to_h)
12
- end
13
-
14
- def id
15
- field_blocks[:id] = proc { @data['id'] }
16
- end
17
-
18
- def field(key, &block)
19
- field_blocks[key] = block
20
- end
21
-
22
- def attribute(key, opts = {})
23
- hash_key = (opts[:key] || key).to_s
24
- field_blocks[key] = proc { @attributes[hash_key] }
25
- end
26
-
27
- def has_many_ids(key, opts = {})
28
- hash_key = (opts[:key] || key).to_s
29
- field_blocks[key] = proc do
30
- @relationships[hash_key]['data'].map { |ri| ri['id'] }
3
+ class Resource
4
+ module DSL
5
+ def type(&block)
6
+ self.type_block = block
31
7
  end
32
- end
33
8
 
34
- def has_many_types(key, opts = {})
35
- hash_key = (opts[:key] || key).to_s
36
- field_blocks[key] = proc do
37
- @relationships[hash_key]['data'].map { |ri| ri['type'] }
9
+ def id(&block)
10
+ self.id_block = block
38
11
  end
39
- end
40
-
41
- def has_many_ids(key, opts = {})
42
- hash_key = (opts[:key] || key).to_s
43
- @relationships[hash_key]['data']['id']
44
- end
45
-
46
- def has_many_ids(key, opts = {})
47
- hash_key = (opts[:key] || key).to_s
48
- @relationships[hash_key]['data']['type']
49
- end
50
-
51
- self.field_blocks = {}
52
- self.validations = {}
53
12
 
54
- def self.inherited(klass)
55
- super
56
- klass.field_blocks = field_blocks.dup
57
- klass.validations = Marshal.load(Marshal.dump(validations))
58
- end
13
+ def attribute(key, &block)
14
+ attr_blocks[key.to_s] = block
15
+ end
59
16
 
60
- private
17
+ def has_one(key, &block)
18
+ has_one_rel_blocks[key.to_s] = block
19
+ end
61
20
 
62
- def add_validations!(hash)
63
- validations[:permitted] = hash[:permitted] if hash[:permitted]
64
- validations[:required] = hash[:required] if hash[:required]
65
- return unless hash[:types]
66
- validations[:types] ||= {}
67
- if hash[:types][:primary]
68
- validations[:types][:primary] = hash[:types][:primary]
21
+ def has_many(key, &block)
22
+ has_many_rel_blocks[key.to_s] = block
69
23
  end
70
- return unless hash[:types][:relationships]
71
- validations[:types][:relationships] ||= {}
72
- validations[:types][:relationships]
73
- .merge!(hash[:types][:relationships])
74
24
  end
75
25
  end
76
26
  end
metadata CHANGED
@@ -1,29 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsonapi-deserializable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1.beta3
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lucas Hosseini
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-25 00:00:00.000000000 Z
11
+ date: 2016-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jsonapi-parser
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.1
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: rake
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
- - - ">="
31
+ - - "~>"
18
32
  - !ruby/object:Gem::Version
19
- version: '0.9'
33
+ version: '11.3'
20
34
  type: :development
21
35
  prerelease: false
22
36
  version_requirements: !ruby/object:Gem::Requirement
23
37
  requirements:
24
- - - ">="
38
+ - - "~>"
25
39
  - !ruby/object:Gem::Version
26
- version: '0.9'
40
+ version: '11.3'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rspec
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -38,8 +52,21 @@ dependencies:
38
52
  - - "~>"
39
53
  - !ruby/object:Gem::Version
40
54
  version: '3.4'
41
- description: DSL for validating incoming JSON API payloads and building custom objects
42
- out of them.
55
+ - !ruby/object:Gem::Dependency
56
+ name: codecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.1'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.1'
69
+ description: DSL for deserializing incoming JSON API payloads into custom hashes.
43
70
  email: lucas.hosseini@gmail.com
44
71
  executables: []
45
72
  extensions: []
@@ -48,11 +75,12 @@ files:
48
75
  - README.md
49
76
  - lib/jsonapi/deserializable.rb
50
77
  - lib/jsonapi/deserializable/relationship.rb
51
- - lib/jsonapi/deserializable/relationship_dsl.rb
78
+ - lib/jsonapi/deserializable/relationship/dsl.rb
52
79
  - lib/jsonapi/deserializable/resource.rb
80
+ - lib/jsonapi/deserializable/resource/configurable.rb
81
+ - lib/jsonapi/deserializable/resource/configuration.rb
53
82
  - lib/jsonapi/deserializable/resource/dsl.rb
54
- - lib/jsonapi/deserializable/resource_dsl.rb
55
- homepage: https://github.com/beauby/jsonapi-deserializable
83
+ homepage: https://github.com/jsonapi-rb/jsonapi-deserializable
56
84
  licenses:
57
85
  - MIT
58
86
  metadata: {}
@@ -67,13 +95,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
67
95
  version: '0'
68
96
  required_rubygems_version: !ruby/object:Gem::Requirement
69
97
  requirements:
70
- - - ">"
98
+ - - ">="
71
99
  - !ruby/object:Gem::Version
72
- version: 1.3.1
100
+ version: '0'
73
101
  requirements: []
74
102
  rubyforge_project:
75
- rubygems_version: 2.5.1
103
+ rubygems_version: 2.6.8
76
104
  signing_key:
77
105
  specification_version: 4
78
- summary: Deserialization of JSONAPI payloads.
106
+ summary: Deserialize JSON API payloads.
79
107
  test_files: []
@@ -1,21 +0,0 @@
1
- module JSONAPI
2
- module Deserializable
3
- module RelationshipDSL
4
- def self.included(base)
5
- base.extend(ClassMethods)
6
- end
7
-
8
- module ClassMethods
9
- def has_one(&block)
10
- block ||= proc { |rel| field key.to_sym => rel }
11
- self.has_one_block = block
12
- end
13
-
14
- def has_many(&block)
15
- block ||= proc { |rel| field key.to_sym => rel }
16
- self.has_many_block = block
17
- end
18
- end
19
- end
20
- end
21
- end
@@ -1,39 +0,0 @@
1
- module JSONAPI
2
- module Deserializable
3
- module ResourceDSL
4
- def self.included(base)
5
- base.extend(ClassMethods)
6
- end
7
-
8
- module ClassMethods
9
- def type(&block)
10
- block ||= proc { |type| field type: type }
11
- self.type_block = block
12
- end
13
-
14
- def id(&block)
15
- block ||= proc { |id| field id: id }
16
- self.id_block = block
17
- end
18
-
19
- def attribute(key, options = {}, &block)
20
- unless block
21
- options[:key] ||= key.to_sym
22
- block = proc { |attr| field key => attr }
23
- end
24
- attr_blocks[key.to_s] = block
25
- end
26
-
27
- def has_one(key, &block)
28
- block ||= proc { |rel| field key.to_sym => rel }
29
- has_one_rel_blocks[key.to_s] = block
30
- end
31
-
32
- def has_many(key, &block)
33
- block ||= proc { |rel| field key.to_sym => rel }
34
- has_many_rel_blocks[key.to_s] = block
35
- end
36
- end
37
- end
38
- end
39
- end