jsonapi-hanami 0.1.1.beta3 → 0.1.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
1
  ---
2
2
  SHA1:
3
- metadata.gz: c246af25ac7b25b1f6205a5857d10f4f2086db47
4
- data.tar.gz: aa835794bf3382750b13aa2b5d8a1d3630fd4163
3
+ metadata.gz: 1671730616527711b4817c7509cccd7f6e1472b9
4
+ data.tar.gz: 17c163b8628d3164ad1d96214d5eb381d1fa201f
5
5
  SHA512:
6
- metadata.gz: a5ce95779eb8fc2e8483a52ea1f52c895f1c8d37035d7e256a9d195b7fe5da87798b19cd6c7f2317c9f721a1ce21a08022bc8c2adac8f8a7825477f3926ed888
7
- data.tar.gz: a91eb46d4cb9db2dfa024d19461216790499223c75762bc89cf79afb84d1602e427274fa86fa387a26473beabef6260d43858ff4c734b560f37bc046955e75f4
6
+ metadata.gz: f375994c77313d3396525dbc27cbd0fd25df41b07ee3ce26abf73f167adcc752a7be7474aa8314c87ed26bc01a120c2f1451c1fa078c4e3d3699e54c19ab5682
7
+ data.tar.gz: 78c7afa495c91aa5e2221ad69ca609baa8184f26a623c3058ef8bdf555d12c98679e09c51223238ba194c847756e4136e923e8fd26a5bc41f5a18b140d34f063
data/README.md CHANGED
@@ -1,10 +1,11 @@
1
1
  # jsonapi-hanami
2
- Hanami integration for [jsonapi-rb](https://github.com/jsonapi-rb/jsonapi-rb).
2
+ Hanami integration for [jsonapi-rb](http://jsonapi-rb.org).
3
3
 
4
4
  ## Status
5
5
 
6
6
  [![Gem Version](https://badge.fury.io/rb/jsonapi-hanami.svg)](https://badge.fury.io/rb/jsonapi-hanami)
7
- [![Build Status](https://secure.travis-ci.org/jsonapi-rb/hanami.svg?branch=master)](http://travis-ci.org/jsonapi-rb/hanami?branch=master)
7
+ [![Build Status](https://secure.travis-ci.org/jsonapi-rb/jsonapi-hanami.svg?branch=master)](http://travis-ci.org/jsonapi-rb/hanami?branch=master)
8
+ [![Gitter chat](https://badges.gitter.im/gitterHQ/gitter.png)](https://gitter.im/jsonapi-rb/Lobby)
8
9
 
9
10
  ## Installation
10
11
 
@@ -21,44 +22,9 @@ Or install it manually as:
21
22
  $ gem install jsonapi-hanami
22
23
  ```
23
24
 
24
- ## Usage
25
+ ## Usage and documentation
25
26
 
26
- ```ruby
27
- module API::Controllers::Posts
28
- class Create
29
- include API::Action
30
- include JSONAPI::Hanami::Action
31
-
32
- deserializable_resource :user, DeserializableCreatePost
33
- # or
34
- deserializable_resource :user do
35
- # ...
36
- end
37
-
38
- params do
39
- # ...
40
- end
41
-
42
- def call(params)
43
- unless params.valid?
44
- self.errors = params.errors
45
- return
46
- end
47
-
48
- repo = UserRepository.new
49
- user = repo.create(params[:user])
50
-
51
- self.data = user
52
- self.meta = { foo: 'bar' }
53
- self.links = { self: 'foo://bar' }
54
- self.jsonapi = { version: '1.0', meta: { foo: 'bar' } }
55
- # Also available:
56
- # self.included = { posts: [:author, comments: [:author]] }
57
- # self.fields = { posts: [:title, :date], users: [:name] }
58
- end
59
- end
60
- end
61
- ```
27
+ See [jsonapi-rb.org/guides](http://jsonapi-rb.org/guides).
62
28
 
63
29
  ## License
64
30
 
@@ -1,5 +1,4 @@
1
1
  require 'jsonapi/deserializable'
2
- require 'jsonapi/parser'
3
2
 
4
3
  module JSONAPI
5
4
  module Hanami
@@ -9,18 +8,20 @@ module JSONAPI
9
8
  end
10
9
 
11
10
  module ClassMethods
12
- def deserializable_resource(key, klass = nil, &block)
13
- if klass.nil?
14
- klass = Class.new(JSONAPI::Deserializable::Resource, &block)
15
- end
16
- use DeserializeResource, key, klass
11
+ def deserializable_resource(key, options = {}, &block)
12
+ _deserializable(key, options,
13
+ JSONAPI::Deserializable::Resource, &block)
17
14
  end
18
15
 
19
- def deserializable_relationship(key, klass = nil, &block)
20
- if klass.nil?
21
- klass = Class.new(JSONAPI::Deserializable::Relationship, &block)
22
- end
23
- use DeserializeRelationship, key, klass
16
+ def deserializable_relationship(key, options = {}, &block)
17
+ _deserializable(key, options,
18
+ JSONAPI::Deserializable::Relationship, &block)
19
+ end
20
+
21
+ # @api private
22
+ def _deserializable(key, options, fallback, &block)
23
+ klass = options[:class] || Class.new(fallback, &block)
24
+ use DeserializationMiddleware, key, klass
24
25
  end
25
26
  end
26
27
 
@@ -37,7 +38,6 @@ module JSONAPI
37
38
 
38
39
  def call(env)
39
40
  body = env[ROUTER_PARSED_BODY]
40
- parser.parse!(body)
41
41
  deserialized_hash = @deserializable_class.call(body)
42
42
  params = env[ROUTER_PARAMS]
43
43
  # TODO(beauby): Actually replace the request body upstream instead
@@ -51,18 +51,6 @@ module JSONAPI
51
51
  @app.call(env)
52
52
  end
53
53
  end
54
-
55
- class DeserializeResource < DeserializationMiddleware
56
- def parser
57
- JSONAPI::Parser::Resource
58
- end
59
- end
60
-
61
- class DeserializeRelationship < DeserializationMiddleware
62
- def parser
63
- JSONAPI::Parser::Relationship
64
- end
65
- end
66
54
  end
67
55
  end
68
56
  end
@@ -38,8 +38,8 @@ module JSONAPI
38
38
  (@_jsonapi ||= {}).merge!(namespace: value)
39
39
  end
40
40
 
41
- def serializable_inferer=(value)
42
- (@_jsonapi ||= {}).merge!(inferer: value)
41
+ def serializable_inferrer=(value)
42
+ (@_jsonapi ||= {}).merge!(inferrer: value)
43
43
  end
44
44
  end
45
45
  end
metadata CHANGED
@@ -1,57 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsonapi-hanami
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-11-18 00:00:00.000000000 Z
11
+ date: 2016-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: jsonapi-deserializable
14
+ name: jsonapi-rb
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 0.1.1.beta3
19
+ version: 0.1.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 0.1.1.beta3
27
- - !ruby/object:Gem::Dependency
28
- name: jsonapi-parser
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - '='
32
- - !ruby/object:Gem::Version
33
- version: 0.1.1.beta3
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - '='
39
- - !ruby/object:Gem::Version
40
- version: 0.1.1.beta3
41
- - !ruby/object:Gem::Dependency
42
- name: jsonapi-serializable
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - '='
46
- - !ruby/object:Gem::Version
47
- version: 0.1.1.beta4
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - '='
53
- - !ruby/object:Gem::Version
54
- version: 0.1.1.beta4
26
+ version: 0.1.1
55
27
  - !ruby/object:Gem::Dependency
56
28
  name: rake
57
29
  requirement: !ruby/object:Gem::Requirement
@@ -95,7 +67,7 @@ files:
95
67
  - lib/jsonapi/hanami/generators/deserializable.rb
96
68
  - lib/jsonapi/hanami/rendering.rb
97
69
  - lib/jsonapi/hanami/rendering/dsl.rb
98
- homepage: https://github.com/jsonapi-rb/hanami
70
+ homepage: https://github.com/jsonapi-rb/jsonapi-hanami
99
71
  licenses:
100
72
  - MIT
101
73
  metadata: {}
@@ -110,12 +82,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
110
82
  version: '0'
111
83
  required_rubygems_version: !ruby/object:Gem::Requirement
112
84
  requirements:
113
- - - ">"
85
+ - - ">="
114
86
  - !ruby/object:Gem::Version
115
- version: 1.3.1
87
+ version: '0'
116
88
  requirements: []
117
89
  rubyforge_project:
118
- rubygems_version: 2.5.1
90
+ rubygems_version: 2.6.8
119
91
  signing_key:
120
92
  specification_version: 4
121
93
  summary: jsonapi-rb integrations for Hanami.