jsonapi-renderer 0.1.2 → 0.1.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: f2ad0e1040698f179b39b373d7aa49c33dfb7b4d
4
- data.tar.gz: ac1e411ed64f21568d6c1844e2ca454ea06c3c3f
3
+ metadata.gz: 64a6b359e09767d1fb82f5c99e5c00493180fee2
4
+ data.tar.gz: 7cbe497431c5af06536206776c5ea4c791085e3c
5
5
  SHA512:
6
- metadata.gz: 9c2d55ff1104119ece672fec2c54f6c5dafbc6e1633337540297c792de794630d59c398591fa8d8c2c47b4ce8b68dd286242143959666a8132253a5b5c7b0798
7
- data.tar.gz: a6433aae68a2d73985a9ffff73fef853a6ede4bca8d614b8ba098bf54d3e8ba03c4692dbcedba8e6a400648b58ecf7411484ff4a890576e317f30a2a6d9178a7
6
+ metadata.gz: 560dd5946e8a744de498eabc762f1f90f4c834a215a2b57e58adba24b9b5f6d6e1e5b878123195b82c2ec6f58f64468cdb530159cd30e5bb99f226134238d66a
7
+ data.tar.gz: 4fdf98ad9829edfc5e254b4df9a7a7f765ee9de05784c76c6f6e35ee73f64b154e75bf40af6953873f0d1cfdeb0dbb096401cc982eac546388930b0219a5741b
data/README.md CHANGED
@@ -8,6 +8,12 @@ Ruby gem for rendering [JSON API](http://jsonapi.org) documents.
8
8
  [![codecov](https://codecov.io/gh/jsonapi-rb/jsonapi-renderer/branch/master/graph/badge.svg)](https://codecov.io/gh/jsonapi-rb/renderer)
9
9
  [![Gitter chat](https://badges.gitter.im/gitterHQ/gitter.png)](https://gitter.im/jsonapi-rb/Lobby)
10
10
 
11
+ ## Resources
12
+
13
+ * Chat: [gitter](http://gitter.im/jsonapi-rb)
14
+ * Twitter: [@jsonapirb](http://twitter.com/jsonapirb)
15
+ * Docs: [jsonapi-rb.org](http://jsonapi-rb.org)
16
+
11
17
  ## Installation
12
18
  ```ruby
13
19
  # In Gemfile
@@ -44,15 +50,15 @@ class ResourceInterface
44
50
 
45
51
  # Returns a hash containing, for each included relationship, an array of the
46
52
  # resources to be included from that one.
47
- # @param [Array<Symbol>] included_relationships The keys of the relationships
53
+ # @param included_relationships [Array<Symbol>] The keys of the relationships
48
54
  # to be included.
49
55
  # @return [Hash{Symbol => Array<#ResourceInterface>}]
50
56
  def jsonapi_related(included_relationships); end
51
57
 
52
58
  # Returns a JSON API-compliant representation of the resource as a hash.
53
- # @param [Hash] options
54
- # @option [Array<Symbol>, Nil] fields The requested fields, or nil.
55
- # @option [Array<Symbol>] include The requested relationships to
59
+ # @param options [Hash]
60
+ # @option fields [Array<Symbol>, Nil] The requested fields, or nil.
61
+ # @option include [Array<Symbol>] The requested relationships to
56
62
  # include (defaults to []).
57
63
  # @return [Hash]
58
64
  def as_jsonapi(options = {}); end
@@ -1,25 +1,32 @@
1
1
  require 'jsonapi/renderer/document'
2
2
 
3
3
  module JSONAPI
4
+ class Renderer
5
+ # Render a JSON API document.
6
+ #
7
+ # @param params [Hash]
8
+ # @option data [(#jsonapi_id, #jsonapi_type, #jsonapi_related, #as_jsonapi),
9
+ # Array<(#jsonapi_id, #jsonapi_type, #jsonapi_related,
10
+ # #as_jsonapi)>,
11
+ # nil] Primary resource(s) to be rendered.
12
+ # @option errors [Array<#jsonapi_id>] Errors to be rendered.
13
+ # @option include Relationships to be included. See
14
+ # JSONAPI::IncludeDirective.
15
+ # @option fields [Hash{Symbol, Array<Symbol>}, Hash{String, Array<String>}]
16
+ # List of requested fields for some or all of the resource types.
17
+ # @option meta [Hash] Non-standard top-level meta information to be
18
+ # included.
19
+ # @option links [Hash] Top-level links to be included.
20
+ # @option jsonapi_object [Hash] JSON API object.
21
+ def render(params)
22
+ Document.new(params).to_hash
23
+ end
24
+ end
25
+
4
26
  module_function
5
27
 
6
- # Render a JSON API document.
7
- #
8
- # @param [Hash] params
9
- # @option [(#jsonapi_id, #jsonapi_type, #jsonapi_related, #as_jsonapi),
10
- # Array<(#jsonapi_id, #jsonapi_type, #jsonapi_related,
11
- # #as_jsonapi)>,
12
- # nil] data Primary resource(s) to be rendered.
13
- # @option [Array<#jsonapi_id>] errors Errors to be rendered.
14
- # @option include Relationships to be included. See
15
- # JSONAPI::IncludeDirective.
16
- # @option [Hash{Symbol, Array<Symbol>}, Hash{String, Array<String>}] fields
17
- # List of requested fields for some or all of the resource types.
18
- # @option [Hash] meta Non-standard top-level meta information to be
19
- # included.
20
- # @option [Hash] links Top-level links to be included.
21
- # @option [Hash] jsonapi_object JSON API object.
28
+ # @see JSONAPI::Renderer#render
22
29
  def render(params)
23
- Renderer::Document.new(params).to_hash
30
+ Renderer.new.render(params)
24
31
  end
25
32
  end
@@ -2,16 +2,16 @@ require 'jsonapi/include_directive'
2
2
  require 'jsonapi/renderer/resources_processor'
3
3
 
4
4
  module JSONAPI
5
- module Renderer
5
+ class Renderer
6
6
  class Document
7
7
  def initialize(params = {})
8
8
  @data = params.fetch(:data, :no_data)
9
9
  @errors = params.fetch(:errors, [])
10
- @meta = params.fetch(:meta, nil)
11
- @links = params.fetch(:links, {})
12
- @fields = _symbolize_fields(params.fetch(:fields, {}))
13
- @jsonapi = params.fetch(:jsonapi, nil)
14
- @include = JSONAPI::IncludeDirective.new(params.fetch(:include, {}))
10
+ @meta = params[:meta]
11
+ @links = params[:links] || {}
12
+ @fields = _symbolize_fields(params[:fields] || {})
13
+ @jsonapi = params[:jsonapi]
14
+ @include = JSONAPI::IncludeDirective.new(params[:include] || {})
15
15
  end
16
16
 
17
17
  def to_hash
@@ -1,7 +1,7 @@
1
1
  require 'set'
2
2
 
3
3
  module JSONAPI
4
- module Renderer
4
+ class Renderer
5
5
  class ResourcesProcessor
6
6
  def initialize(resources, include, fields)
7
7
  @resources = resources
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsonapi-renderer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
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-12-12 00:00:00.000000000 Z
11
+ date: 2017-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -84,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
84
  version: '0'
85
85
  requirements: []
86
86
  rubyforge_project:
87
- rubygems_version: 2.6.8
87
+ rubygems_version: 2.6.12
88
88
  signing_key:
89
89
  specification_version: 4
90
90
  summary: Render JSONAPI documents.