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 +4 -4
- data/README.md +10 -4
- data/lib/jsonapi/renderer.rb +24 -17
- data/lib/jsonapi/renderer/document.rb +6 -6
- data/lib/jsonapi/renderer/resources_processor.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 64a6b359e09767d1fb82f5c99e5c00493180fee2
|
4
|
+
data.tar.gz: 7cbe497431c5af06536206776c5ea4c791085e3c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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>]
|
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]
|
54
|
-
# @option [Array<Symbol>, Nil]
|
55
|
-
# @option [Array<Symbol>]
|
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
|
data/lib/jsonapi/renderer.rb
CHANGED
@@ -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
|
-
#
|
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
|
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
|
-
|
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
|
11
|
-
@links = params
|
12
|
-
@fields = _symbolize_fields(params
|
13
|
-
@jsonapi = params
|
14
|
-
@include = JSONAPI::IncludeDirective.new(params
|
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
|
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.
|
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:
|
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.
|
87
|
+
rubygems_version: 2.6.12
|
88
88
|
signing_key:
|
89
89
|
specification_version: 4
|
90
90
|
summary: Render JSONAPI documents.
|