@@ -7,108 +7,28 @@ The renderer takes your business objects (which can be any ruby objects: POROs,
77ActiveRecord models, or even plain hashes), along with some optional parameters
88(` include ` , ` fields ` , etc.), and builds the JSON API document.
99
10- ## Plain ruby
10+ The available global options are:
1111
12- When using jsonapi-rb in plain ruby (or from within a framework outside of a
13- controller), you can render a document as follows:
14-
15- ``` ruby
16- JSONAPI ::Serializable ::SuccessRenderer .render(posts)
17- ```
18-
19- You can also pass options to the renderer:
20-
21- ``` ruby
22- JSONAPI ::Serializable ::SuccessRenderer .render(posts,
23- include: [:author , comments: [:author ]],
24- fields: { users: [:name , :email ],
25- posts: [:title , :content ] })
26- ```
27-
28- For a comprehensive list of renderer options, see [ Renderer options] ( ) .
29-
30- ## Ruby on Rails
31-
32- When using jsonapi-rb with Rails (via the jsonapi-rails gem), rendering is done
33- via the usual ` render ` controller method:
34-
35- ``` ruby
36- render jsonapi: posts
37- ```
38- and options are passed as named arguments:
39-
40- ``` ruby
41- render jsonapi: posts,
42- include: [:author , comments: [:author ]],
43- fields: { users: [:name , :email ],
44- posts: [:title , :content ] }
45- ```
46-
47- For a comprehensive list of renderer options, see [ Renderer options] ( ) .
48-
49- ## Hanami
50-
51- When using jsonapi-rb with Hanami (via the jsonapi-hanami gem), enabling of
52- jsonapi-rb features is opt-in, and is done by including
53- ` JSONAPI::Hanami::Action ` in your actions.
54- Rendering is done by setting options directly on the controller action instance.
55- The primary data is set via the ` self.data ` setter.
56-
57- Exposures are available from within the ` SerializableResource ` class as instance
58- variables.
59-
60- Example:
61-
62- ``` ruby
63- module API ::Controllers ::Posts
64- class Create
65- include API ::Action
66- include JSONAPI ::Hanami ::Action
67-
68- expose :url_helpers
69-
70- def call (params )
71- # ...
72- @url_helpers = routes # Will be available inside serializable resources.
73-
74- self .data = posts
75- self .include = [:author , comments: [:author ]]
76- self .fields = { users: [:name , :email ],
77- posts: [:title , :content ] }
78- end
79- end
80- end
81- ```
82-
83- For a comprehensive list of renderer options, see [ Renderer options] ( ) .
84-
85- ## Renderer options
86-
87- The available options are:
88-
89- + data-related options:
90- + ` include ` : the related resources to include in the document. This option can
91- be specified as a string (e.g. ` "author,comments.author" ` ), or as an array/
92- hash of symbols (e.g. ` [:author, comments: [:author]] ` ).
93- + ` fields ` : a restricted set of fields for some or all resources. This option
94- can be specified as a hash of arrays of symbols (e.g.
95- ` { users: [:name, :email], posts: [:title, :content] } ` ).
96- + ` expose ` : a hash of arbitrary variables that will be made available to the
97- serializable resources as instance variables.
9812+ serializable resource class related options:
99- + ` inferrer ` : a hash globally mapping model class names to serializable resource
100- class names.
101- + ` namespace ` : the namespace in which to look for serializable resource
102- classes. This option can be specified as a constant (e.g. ` V2 ` ), or as a
103- string (e.g. ` "V2" ` ).
104- + ` class ` : the serializable resource class(es) to be used for the primary
105- data. This option can be specified as a constant (e.g. ` SerializablePost ` ),
106- as a string (e.g. ` "SerializablePost" ` ), or as a hash (e.g.
107- ` { Article: "SerializableFormattedArticle", Letter: "SerializableFormattedLetter" } ` ).
13+ + ` class ` : a hash globally mapping model class names to serializable resource
14+ class names.
10815+ top level properties:
10916 + ` links ` : a set of top level links. This option can be specified as a hash.
11017 + ` meta ` : top level meta information. This option can be specified as a hash.
11118 + ` jsonapi ` : top level ` jsonapi ` object. This option can be specified as a
11219 hash.
11320+ framework-specific options: in Hanami and Rails, the usual options such as
11421` status ` are respected.
22+
23+ When serializing resources and relationships, the following
24+ data-related options are also available:
25+
26+ + ` include ` : the related resources to include in the document. This option can
27+ be specified as a string (e.g. ` "author,comments.author" ` ), or as an array/
28+ hash of symbols (e.g. ` [:author, comments: [:author]] ` ).
29+ + ` fields ` : a restricted set of fields for some or all resources. This option
30+ can be specified as a hash of arrays of symbols (e.g.
31+ ` { users: [:name, :email], posts: [:title, :content] } ` ).
32+ + ` expose ` : a hash of arbitrary variables that will be made available to the
33+ serializable resources as instance variables.
34+ + ` cache ` : a cache supporting ` fetch_multi ` for fragment caching.
0 commit comments