jsonapi_compliable 0.6.4 → 0.6.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -1
  3. data/.travis.yml +11 -3
  4. data/.yardopts +1 -0
  5. data/README.md +10 -1
  6. data/Rakefile +1 -0
  7. data/docs/JsonapiCompliable.html +202 -0
  8. data/docs/JsonapiCompliable/Adapters.html +119 -0
  9. data/docs/JsonapiCompliable/Adapters/Abstract.html +2285 -0
  10. data/docs/JsonapiCompliable/Adapters/ActiveRecord.html +2151 -0
  11. data/docs/JsonapiCompliable/Adapters/ActiveRecordSideloading.html +582 -0
  12. data/docs/JsonapiCompliable/Adapters/Null.html +1682 -0
  13. data/docs/JsonapiCompliable/Base.html +1395 -0
  14. data/docs/JsonapiCompliable/Deserializer.html +835 -0
  15. data/docs/JsonapiCompliable/Errors.html +115 -0
  16. data/docs/JsonapiCompliable/Errors/BadFilter.html +124 -0
  17. data/docs/JsonapiCompliable/Errors/StatNotFound.html +266 -0
  18. data/docs/JsonapiCompliable/Errors/UnsupportedPageSize.html +264 -0
  19. data/docs/JsonapiCompliable/Errors/ValidationError.html +124 -0
  20. data/docs/JsonapiCompliable/Extensions.html +117 -0
  21. data/docs/JsonapiCompliable/Extensions/BooleanAttribute.html +212 -0
  22. data/docs/JsonapiCompliable/Extensions/BooleanAttribute/ClassMethods.html +229 -0
  23. data/docs/JsonapiCompliable/Extensions/ExtraAttribute.html +242 -0
  24. data/docs/JsonapiCompliable/Extensions/ExtraAttribute/ClassMethods.html +237 -0
  25. data/docs/JsonapiCompliable/Query.html +1099 -0
  26. data/docs/JsonapiCompliable/Rails.html +211 -0
  27. data/docs/JsonapiCompliable/Resource.html +5241 -0
  28. data/docs/JsonapiCompliable/Scope.html +703 -0
  29. data/docs/JsonapiCompliable/Scoping.html +117 -0
  30. data/docs/JsonapiCompliable/Scoping/Base.html +843 -0
  31. data/docs/JsonapiCompliable/Scoping/DefaultFilter.html +318 -0
  32. data/docs/JsonapiCompliable/Scoping/ExtraFields.html +301 -0
  33. data/docs/JsonapiCompliable/Scoping/Filter.html +313 -0
  34. data/docs/JsonapiCompliable/Scoping/Filterable.html +364 -0
  35. data/docs/JsonapiCompliable/Scoping/Paginate.html +613 -0
  36. data/docs/JsonapiCompliable/Scoping/Sort.html +454 -0
  37. data/docs/JsonapiCompliable/SerializableTempId.html +216 -0
  38. data/docs/JsonapiCompliable/Sideload.html +2484 -0
  39. data/docs/JsonapiCompliable/Stats.html +117 -0
  40. data/docs/JsonapiCompliable/Stats/DSL.html +999 -0
  41. data/docs/JsonapiCompliable/Stats/Payload.html +391 -0
  42. data/docs/JsonapiCompliable/Util.html +117 -0
  43. data/docs/JsonapiCompliable/Util/FieldParams.html +228 -0
  44. data/docs/JsonapiCompliable/Util/Hash.html +471 -0
  45. data/docs/JsonapiCompliable/Util/IncludeParams.html +299 -0
  46. data/docs/JsonapiCompliable/Util/Persistence.html +435 -0
  47. data/docs/JsonapiCompliable/Util/RelationshipPayload.html +563 -0
  48. data/docs/JsonapiCompliable/Util/RenderOptions.html +250 -0
  49. data/docs/JsonapiCompliable/Util/ValidationResponse.html +532 -0
  50. data/docs/_index.html +527 -0
  51. data/docs/class_list.html +51 -0
  52. data/docs/css/common.css +1 -0
  53. data/docs/css/full_list.css +58 -0
  54. data/docs/css/style.css +492 -0
  55. data/docs/file.README.html +99 -0
  56. data/docs/file_list.html +56 -0
  57. data/docs/frames.html +17 -0
  58. data/docs/index.html +99 -0
  59. data/docs/js/app.js +248 -0
  60. data/docs/js/full_list.js +216 -0
  61. data/docs/js/jquery.js +4 -0
  62. data/docs/method_list.html +1731 -0
  63. data/docs/top-level-namespace.html +110 -0
  64. data/gemfiles/rails_5.gemfile +1 -1
  65. data/lib/jsonapi_compliable/adapters/abstract.rb +267 -4
  66. data/lib/jsonapi_compliable/adapters/active_record.rb +23 -1
  67. data/lib/jsonapi_compliable/adapters/null.rb +43 -3
  68. data/lib/jsonapi_compliable/base.rb +182 -33
  69. data/lib/jsonapi_compliable/deserializer.rb +90 -21
  70. data/lib/jsonapi_compliable/extensions/boolean_attribute.rb +12 -0
  71. data/lib/jsonapi_compliable/extensions/extra_attribute.rb +32 -0
  72. data/lib/jsonapi_compliable/extensions/temp_id.rb +11 -0
  73. data/lib/jsonapi_compliable/query.rb +94 -2
  74. data/lib/jsonapi_compliable/rails.rb +8 -0
  75. data/lib/jsonapi_compliable/resource.rb +548 -11
  76. data/lib/jsonapi_compliable/scope.rb +43 -1
  77. data/lib/jsonapi_compliable/scoping/base.rb +59 -8
  78. data/lib/jsonapi_compliable/scoping/default_filter.rb +33 -0
  79. data/lib/jsonapi_compliable/scoping/extra_fields.rb +33 -0
  80. data/lib/jsonapi_compliable/scoping/filter.rb +29 -2
  81. data/lib/jsonapi_compliable/scoping/filterable.rb +4 -0
  82. data/lib/jsonapi_compliable/scoping/paginate.rb +33 -0
  83. data/lib/jsonapi_compliable/scoping/sort.rb +18 -0
  84. data/lib/jsonapi_compliable/sideload.rb +229 -1
  85. data/lib/jsonapi_compliable/stats/dsl.rb +44 -0
  86. data/lib/jsonapi_compliable/stats/payload.rb +20 -0
  87. data/lib/jsonapi_compliable/util/field_params.rb +1 -0
  88. data/lib/jsonapi_compliable/util/hash.rb +18 -0
  89. data/lib/jsonapi_compliable/util/include_params.rb +22 -0
  90. data/lib/jsonapi_compliable/util/persistence.rb +13 -3
  91. data/lib/jsonapi_compliable/util/relationship_payload.rb +2 -0
  92. data/lib/jsonapi_compliable/util/render_options.rb +2 -0
  93. data/lib/jsonapi_compliable/util/validation_response.rb +16 -0
  94. data/lib/jsonapi_compliable/version.rb +1 -1
  95. metadata +60 -5
  96. data/gemfiles/rails_4.gemfile.lock +0 -208
  97. data/gemfiles/rails_5.gemfile.lock +0 -212
  98. data/lib/jsonapi_compliable/write.rb +0 -93
@@ -0,0 +1,318 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>
7
+ Class: JsonapiCompliable::Scoping::DefaultFilter
8
+
9
+ &mdash; Documentation by YARD 0.9.9
10
+
11
+ </title>
12
+
13
+ <link rel="stylesheet" href="../../css/style.css" type="text/css" charset="utf-8" />
14
+
15
+ <link rel="stylesheet" href="../../css/common.css" type="text/css" charset="utf-8" />
16
+
17
+ <script type="text/javascript" charset="utf-8">
18
+ pathId = "JsonapiCompliable::Scoping::DefaultFilter";
19
+ relpath = '../../';
20
+ </script>
21
+
22
+
23
+ <script type="text/javascript" charset="utf-8" src="../../js/jquery.js"></script>
24
+
25
+ <script type="text/javascript" charset="utf-8" src="../../js/app.js"></script>
26
+
27
+
28
+ </head>
29
+ <body>
30
+ <div class="nav_wrap">
31
+ <iframe id="nav" src="../../class_list.html?1"></iframe>
32
+ <div id="resizer"></div>
33
+ </div>
34
+
35
+ <div id="main" tabindex="-1">
36
+ <div id="header">
37
+ <div id="menu">
38
+
39
+ <a href="../../_index.html">Index (D)</a> &raquo;
40
+ <span class='title'><span class='object_link'><a href="../../JsonapiCompliable.html" title="JsonapiCompliable (module)">JsonapiCompliable</a></span></span> &raquo; <span class='title'><span class='object_link'><a href="../Scoping.html" title="JsonapiCompliable::Scoping (module)">Scoping</a></span></span>
41
+ &raquo;
42
+ <span class="title">DefaultFilter</span>
43
+
44
+ </div>
45
+
46
+ <div id="search">
47
+
48
+ <a class="full_list_link" id="class_list_link"
49
+ href="../../class_list.html">
50
+
51
+ <svg width="24" height="24">
52
+ <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
53
+ <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
54
+ <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
55
+ </svg>
56
+ </a>
57
+
58
+ </div>
59
+ <div class="clear"></div>
60
+ </div>
61
+
62
+ <div id="content"><h1>Class: JsonapiCompliable::Scoping::DefaultFilter
63
+
64
+
65
+
66
+ </h1>
67
+ <div class="box_info">
68
+
69
+ <dl>
70
+ <dt>Inherits:</dt>
71
+ <dd>
72
+ <span class="inheritName"><span class='object_link'><a href="Base.html" title="JsonapiCompliable::Scoping::Base (class)">Base</a></span></span>
73
+
74
+ <ul class="fullTree">
75
+ <li>Object</li>
76
+
77
+ <li class="next"><span class='object_link'><a href="Base.html" title="JsonapiCompliable::Scoping::Base (class)">Base</a></span></li>
78
+
79
+ <li class="next">JsonapiCompliable::Scoping::DefaultFilter</li>
80
+
81
+ </ul>
82
+ <a href="#" class="inheritanceTree">show all</a>
83
+
84
+ </dd>
85
+ </dl>
86
+
87
+
88
+
89
+
90
+
91
+
92
+ <dl>
93
+ <dt>Includes:</dt>
94
+ <dd><span class='object_link'><a href="Filterable.html" title="JsonapiCompliable::Scoping::Filterable (module)">Filterable</a></span></dd>
95
+ </dl>
96
+
97
+
98
+
99
+
100
+
101
+
102
+ <dl>
103
+ <dt>Defined in:</dt>
104
+ <dd>lib/jsonapi_compliable/scoping/default_filter.rb</dd>
105
+ </dl>
106
+
107
+ </div>
108
+
109
+ <h2>Overview</h2><div class="docstring">
110
+ <div class="discussion">
111
+
112
+ <p>Default filters apply to every request, unless specifically overridden in
113
+ the request.</p>
114
+
115
+ <p>Maybe we only want to show active posts:</p>
116
+
117
+ <pre class="code ruby"><code class="ruby"><span class='kw'>class</span> <span class='const'>PostResource</span> <span class='op'>&lt;</span> <span class='const'>ApplicationResource</span>
118
+ <span class='comment'># ... code ...
119
+ </span> <span class='id identifier rubyid_default_filter'>default_filter</span> <span class='symbol'>:active</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_scope'>scope</span><span class='op'>|</span>
120
+ <span class='id identifier rubyid_scope'>scope</span><span class='period'>.</span><span class='id identifier rubyid_where'>where</span><span class='lparen'>(</span><span class='label'>active:</span> <span class='kw'>true</span><span class='rparen'>)</span>
121
+ <span class='kw'>end</span>
122
+ <span class='kw'>end</span>
123
+ </code></pre>
124
+
125
+ <p>But if the user is an admin and specifically requests inactive posts:</p>
126
+
127
+ <pre class="code ruby"><code class="ruby"><span class='kw'>class</span> <span class='const'>PostResource</span> <span class='op'>&lt;</span> <span class='const'>ApplicationResource</span>
128
+ <span class='comment'># ... code ...
129
+ </span> <span class='id identifier rubyid_allow_filter'>allow_filter</span> <span class='symbol'>:active</span><span class='comma'>,</span> <span class='label'>if:</span> <span class='id identifier rubyid_admin?'>admin?</span>
130
+
131
+ <span class='id identifier rubyid_default_filter'>default_filter</span> <span class='symbol'>:active</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_scope'>scope</span><span class='op'>|</span>
132
+ <span class='id identifier rubyid_scope'>scope</span><span class='period'>.</span><span class='id identifier rubyid_where'>where</span><span class='lparen'>(</span><span class='label'>active:</span> <span class='kw'>true</span><span class='rparen'>)</span>
133
+ <span class='kw'>end</span>
134
+ <span class='kw'>end</span>
135
+
136
+ <span class='comment'># Now a GET /posts?filter[active]=false will return inactive posts
137
+ </span><span class='comment'># if the user is an admin.
138
+ </span></code></pre>
139
+
140
+
141
+ </div>
142
+ </div>
143
+ <div class="tags">
144
+
145
+
146
+ <p class="tag_title">See Also:</p>
147
+ <ul class="see">
148
+
149
+ <li><span class='object_link'><a href="../Resource.html#default_filter-class_method" title="JsonapiCompliable::Resource.default_filter (method)">Resource.default_filter</a></span></li>
150
+
151
+ <li><span class='object_link'><a href="../Resource.html#allow_filter-class_method" title="JsonapiCompliable::Resource.allow_filter (method)">Resource.allow_filter</a></span></li>
152
+
153
+ </ul>
154
+
155
+ </div>
156
+
157
+
158
+
159
+
160
+
161
+ <h2>Instance Attribute Summary</h2>
162
+
163
+ <h3 class="inherited">Attributes inherited from <span class='object_link'><a href="Base.html" title="JsonapiCompliable::Scoping::Base (class)">Base</a></span></h3>
164
+ <p class="inherited"><span class='object_link'><a href="Base.html#query_hash-instance_method" title="JsonapiCompliable::Scoping::Base#query_hash (method)">#query_hash</a></span>, <span class='object_link'><a href="Base.html#resource-instance_method" title="JsonapiCompliable::Scoping::Base#resource (method)">#resource</a></span></p>
165
+
166
+
167
+
168
+ <h2>
169
+ Instance Method Summary
170
+ <small><a href="#" class="summary_toggle">collapse</a></small>
171
+ </h2>
172
+
173
+ <ul class="summary">
174
+
175
+ <li class="public ">
176
+ <span class="summary_signature">
177
+
178
+ <a href="#apply-instance_method" title="#apply (instance method)">#<strong>apply</strong> &#x21d2; Object </a>
179
+
180
+
181
+
182
+ </span>
183
+
184
+
185
+
186
+
187
+
188
+
189
+
190
+
191
+
192
+ <span class="summary_desc"><div class='inline'>
193
+ <p>Apply the default filtering logic.</p>
194
+ </div></span>
195
+
196
+ </li>
197
+
198
+
199
+ </ul>
200
+
201
+
202
+
203
+
204
+
205
+
206
+
207
+
208
+
209
+
210
+
211
+ <h3 class="inherited">Methods included from <span class='object_link'><a href="Filterable.html" title="JsonapiCompliable::Scoping::Filterable (module)">Filterable</a></span></h3>
212
+ <p class="inherited"><span class='object_link'><a href="Filterable.html#filter_param-instance_method" title="JsonapiCompliable::Scoping::Filterable#filter_param (method)">#filter_param</a></span>, <span class='object_link'><a href="Filterable.html#find_filter-instance_method" title="JsonapiCompliable::Scoping::Filterable#find_filter (method)">#find_filter</a></span>, <span class='object_link'><a href="Filterable.html#find_filter!-instance_method" title="JsonapiCompliable::Scoping::Filterable#find_filter! (method)">#find_filter!</a></span></p>
213
+
214
+
215
+
216
+
217
+
218
+
219
+
220
+
221
+
222
+ <h3 class="inherited">Methods inherited from <span class='object_link'><a href="Base.html" title="JsonapiCompliable::Scoping::Base (class)">Base</a></span></h3>
223
+ <p class="inherited"><span class='object_link'><a href="Base.html#apply%3F-instance_method" title="JsonapiCompliable::Scoping::Base#apply? (method)">#apply?</a></span>, <span class='object_link'><a href="Base.html#apply_custom_scope-instance_method" title="JsonapiCompliable::Scoping::Base#apply_custom_scope (method)">#apply_custom_scope</a></span>, <span class='object_link'><a href="Base.html#apply_standard_scope-instance_method" title="JsonapiCompliable::Scoping::Base#apply_standard_scope (method)">#apply_standard_scope</a></span>, <span class='object_link'><a href="Base.html#initialize-instance_method" title="JsonapiCompliable::Scoping::Base#initialize (method)">#initialize</a></span></p>
224
+ <div id="constructor_details" class="method_details_list">
225
+ <h2>Constructor Details</h2>
226
+
227
+ <p class="notice">This class inherits a constructor from <span class='object_link'><a href="Base.html#initialize-instance_method" title="JsonapiCompliable::Scoping::Base#initialize (method)">JsonapiCompliable::Scoping::Base</a></span></p>
228
+
229
+ </div>
230
+
231
+
232
+ <div id="instance_method_details" class="method_details_list">
233
+ <h2>Instance Method Details</h2>
234
+
235
+
236
+ <div class="method_details first">
237
+ <h3 class="signature first" id="apply-instance_method">
238
+
239
+ #<strong>apply</strong> &#x21d2; <tt>Object</tt>
240
+
241
+
242
+
243
+
244
+
245
+ </h3><div class="docstring">
246
+ <div class="discussion">
247
+
248
+ <p>Apply the default filtering logic. Loop through each defined default
249
+ filter, and apply the default proc unless an explicit override is requested</p>
250
+
251
+
252
+ </div>
253
+ </div>
254
+ <div class="tags">
255
+
256
+ <p class="tag_title">Returns:</p>
257
+ <ul class="return">
258
+
259
+ <li>
260
+
261
+
262
+ <span class='type'></span>
263
+
264
+
265
+
266
+
267
+ <div class='inline'>
268
+ <p>scope the scope object we are chaining/modifying</p>
269
+ </div>
270
+
271
+ </li>
272
+
273
+ </ul>
274
+
275
+ </div><table class="source_code">
276
+ <tr>
277
+ <td>
278
+ <pre class="lines">
279
+
280
+
281
+ 38
282
+ 39
283
+ 40
284
+ 41
285
+ 42
286
+ 43
287
+ 44
288
+ 45</pre>
289
+ </td>
290
+ <td>
291
+ <pre class="code"><span class="info file"># File 'lib/jsonapi_compliable/scoping/default_filter.rb', line 38</span>
292
+
293
+ <span class='kw'>def</span> <span class='id identifier rubyid_apply'>apply</span>
294
+ <span class='id identifier rubyid_resource'>resource</span><span class='period'>.</span><span class='id identifier rubyid_default_filters'>default_filters</span><span class='period'>.</span><span class='id identifier rubyid_each_pair'>each_pair</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_name'>name</span><span class='comma'>,</span> <span class='id identifier rubyid_opts'>opts</span><span class='op'>|</span>
295
+ <span class='kw'>next</span> <span class='kw'>if</span> <span class='id identifier rubyid_overridden?'>overridden?</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span>
296
+ <span class='ivar'>@scope</span> <span class='op'>=</span> <span class='id identifier rubyid_opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:filter</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_call'>call</span><span class='lparen'>(</span><span class='ivar'>@scope</span><span class='rparen'>)</span>
297
+ <span class='kw'>end</span>
298
+
299
+ <span class='ivar'>@scope</span>
300
+ <span class='kw'>end</span></pre>
301
+ </td>
302
+ </tr>
303
+ </table>
304
+ </div>
305
+
306
+ </div>
307
+
308
+ </div>
309
+
310
+ <div id="footer">
311
+ Generated on Fri May 5 15:53:23 2017 by
312
+ <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
313
+ 0.9.9 (ruby-2.3.0).
314
+ </div>
315
+
316
+ </div>
317
+ </body>
318
+ </html>
@@ -0,0 +1,301 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>
7
+ Class: JsonapiCompliable::Scoping::ExtraFields
8
+
9
+ &mdash; Documentation by YARD 0.9.9
10
+
11
+ </title>
12
+
13
+ <link rel="stylesheet" href="../../css/style.css" type="text/css" charset="utf-8" />
14
+
15
+ <link rel="stylesheet" href="../../css/common.css" type="text/css" charset="utf-8" />
16
+
17
+ <script type="text/javascript" charset="utf-8">
18
+ pathId = "JsonapiCompliable::Scoping::ExtraFields";
19
+ relpath = '../../';
20
+ </script>
21
+
22
+
23
+ <script type="text/javascript" charset="utf-8" src="../../js/jquery.js"></script>
24
+
25
+ <script type="text/javascript" charset="utf-8" src="../../js/app.js"></script>
26
+
27
+
28
+ </head>
29
+ <body>
30
+ <div class="nav_wrap">
31
+ <iframe id="nav" src="../../class_list.html?1"></iframe>
32
+ <div id="resizer"></div>
33
+ </div>
34
+
35
+ <div id="main" tabindex="-1">
36
+ <div id="header">
37
+ <div id="menu">
38
+
39
+ <a href="../../_index.html">Index (E)</a> &raquo;
40
+ <span class='title'><span class='object_link'><a href="../../JsonapiCompliable.html" title="JsonapiCompliable (module)">JsonapiCompliable</a></span></span> &raquo; <span class='title'><span class='object_link'><a href="../Scoping.html" title="JsonapiCompliable::Scoping (module)">Scoping</a></span></span>
41
+ &raquo;
42
+ <span class="title">ExtraFields</span>
43
+
44
+ </div>
45
+
46
+ <div id="search">
47
+
48
+ <a class="full_list_link" id="class_list_link"
49
+ href="../../class_list.html">
50
+
51
+ <svg width="24" height="24">
52
+ <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
53
+ <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
54
+ <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
55
+ </svg>
56
+ </a>
57
+
58
+ </div>
59
+ <div class="clear"></div>
60
+ </div>
61
+
62
+ <div id="content"><h1>Class: JsonapiCompliable::Scoping::ExtraFields
63
+
64
+
65
+
66
+ </h1>
67
+ <div class="box_info">
68
+
69
+ <dl>
70
+ <dt>Inherits:</dt>
71
+ <dd>
72
+ <span class="inheritName"><span class='object_link'><a href="Base.html" title="JsonapiCompliable::Scoping::Base (class)">Base</a></span></span>
73
+
74
+ <ul class="fullTree">
75
+ <li>Object</li>
76
+
77
+ <li class="next"><span class='object_link'><a href="Base.html" title="JsonapiCompliable::Scoping::Base (class)">Base</a></span></li>
78
+
79
+ <li class="next">JsonapiCompliable::Scoping::ExtraFields</li>
80
+
81
+ </ul>
82
+ <a href="#" class="inheritanceTree">show all</a>
83
+
84
+ </dd>
85
+ </dl>
86
+
87
+
88
+
89
+
90
+
91
+
92
+
93
+
94
+
95
+
96
+
97
+ <dl>
98
+ <dt>Defined in:</dt>
99
+ <dd>lib/jsonapi_compliable/scoping/extra_fields.rb</dd>
100
+ </dl>
101
+
102
+ </div>
103
+
104
+ <h2>Overview</h2><div class="docstring">
105
+ <div class="discussion">
106
+
107
+ <p>Apply logic when an extra field is requested. Useful for eager loading
108
+ associations used to compute the extra field.</p>
109
+
110
+ <p>Given a Resource</p>
111
+
112
+ <pre class="code ruby"><code class="ruby"><span class='kw'>class</span> <span class='const'>PersonResource</span> <span class='op'>&lt;</span> <span class='const'>ApplicationResource</span>
113
+ <span class='id identifier rubyid_extra_field'>extra_field</span> <span class='symbol'>:net_worth</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_scope'>scope</span><span class='op'>|</span>
114
+ <span class='id identifier rubyid_scope'>scope</span><span class='period'>.</span><span class='id identifier rubyid_includes'>includes</span><span class='lparen'>(</span><span class='symbol'>:assets</span><span class='rparen'>)</span>
115
+ <span class='kw'>end</span>
116
+ <span class='kw'>end</span>
117
+ </code></pre>
118
+
119
+ <p>And a corresponding serializer:</p>
120
+
121
+ <pre class="code ruby"><code class="ruby"><span class='kw'>class</span> <span class='const'>SerializablePerson</span> <span class='op'>&lt;</span> <span class='const'>JSONAPI</span><span class='op'>::</span><span class='const'>Serializable</span><span class='op'>::</span><span class='const'>Resource</span>
122
+ <span class='id identifier rubyid_extra_attribute'>extra_attribute</span> <span class='symbol'>:net_worth</span> <span class='kw'>do</span>
123
+ <span class='ivar'>@object</span><span class='period'>.</span><span class='id identifier rubyid_assets'>assets</span><span class='period'>.</span><span class='id identifier rubyid_sum'>sum</span><span class='lparen'>(</span><span class='op'>&amp;</span><span class='symbol'>:value</span><span class='rparen'>)</span>
124
+ <span class='kw'>end</span>
125
+ <span class='kw'>end</span>
126
+ </code></pre>
127
+
128
+ <p>When the user requests the extra field &#39;net_worth&#39;:</p>
129
+
130
+ <pre class="code ruby"><code class="ruby">GET /people?extra_fields[people]=net_worth</code></pre>
131
+
132
+ <p>The <code>assets</code> will be eager loaded and the &#39;net_worth&#39;
133
+ attribute will be present in the response. If this field is not explicitly
134
+ requested, none of this logic fires.</p>
135
+
136
+
137
+ </div>
138
+ </div>
139
+ <div class="tags">
140
+
141
+
142
+ <p class="tag_title">See Also:</p>
143
+ <ul class="see">
144
+
145
+ <li><span class='object_link'><a href="../Resource.html#extra_field-class_method" title="JsonapiCompliable::Resource.extra_field (method)">Resource.extra_field</a></span></li>
146
+
147
+ <li><span class='object_link'><a href="../Extensions/ExtraAttribute.html" title="JsonapiCompliable::Extensions::ExtraAttribute (module)">Extensions::ExtraAttribute</a></span></li>
148
+
149
+ </ul>
150
+
151
+ </div>
152
+
153
+
154
+
155
+
156
+
157
+ <h2>Instance Attribute Summary</h2>
158
+
159
+ <h3 class="inherited">Attributes inherited from <span class='object_link'><a href="Base.html" title="JsonapiCompliable::Scoping::Base (class)">Base</a></span></h3>
160
+ <p class="inherited"><span class='object_link'><a href="Base.html#query_hash-instance_method" title="JsonapiCompliable::Scoping::Base#query_hash (method)">#query_hash</a></span>, <span class='object_link'><a href="Base.html#resource-instance_method" title="JsonapiCompliable::Scoping::Base#resource (method)">#resource</a></span></p>
161
+
162
+
163
+
164
+ <h2>
165
+ Instance Method Summary
166
+ <small><a href="#" class="summary_toggle">collapse</a></small>
167
+ </h2>
168
+
169
+ <ul class="summary">
170
+
171
+ <li class="public ">
172
+ <span class="summary_signature">
173
+
174
+ <a href="#apply-instance_method" title="#apply (instance method)">#<strong>apply</strong> &#x21d2; Object </a>
175
+
176
+
177
+
178
+ </span>
179
+
180
+
181
+
182
+
183
+
184
+
185
+
186
+
187
+
188
+ <span class="summary_desc"><div class='inline'>
189
+ <p>Loop through all requested extra fields.</p>
190
+ </div></span>
191
+
192
+ </li>
193
+
194
+
195
+ </ul>
196
+
197
+
198
+
199
+
200
+
201
+
202
+
203
+
204
+
205
+
206
+
207
+ <h3 class="inherited">Methods inherited from <span class='object_link'><a href="Base.html" title="JsonapiCompliable::Scoping::Base (class)">Base</a></span></h3>
208
+ <p class="inherited"><span class='object_link'><a href="Base.html#apply%3F-instance_method" title="JsonapiCompliable::Scoping::Base#apply? (method)">#apply?</a></span>, <span class='object_link'><a href="Base.html#apply_custom_scope-instance_method" title="JsonapiCompliable::Scoping::Base#apply_custom_scope (method)">#apply_custom_scope</a></span>, <span class='object_link'><a href="Base.html#apply_standard_scope-instance_method" title="JsonapiCompliable::Scoping::Base#apply_standard_scope (method)">#apply_standard_scope</a></span>, <span class='object_link'><a href="Base.html#initialize-instance_method" title="JsonapiCompliable::Scoping::Base#initialize (method)">#initialize</a></span></p>
209
+ <div id="constructor_details" class="method_details_list">
210
+ <h2>Constructor Details</h2>
211
+
212
+ <p class="notice">This class inherits a constructor from <span class='object_link'><a href="Base.html#initialize-instance_method" title="JsonapiCompliable::Scoping::Base#initialize (method)">JsonapiCompliable::Scoping::Base</a></span></p>
213
+
214
+ </div>
215
+
216
+
217
+ <div id="instance_method_details" class="method_details_list">
218
+ <h2>Instance Method Details</h2>
219
+
220
+
221
+ <div class="method_details first">
222
+ <h3 class="signature first" id="apply-instance_method">
223
+
224
+ #<strong>apply</strong> &#x21d2; <tt>Object</tt>
225
+
226
+
227
+
228
+
229
+
230
+ </h3><div class="docstring">
231
+ <div class="discussion">
232
+
233
+ <p>Loop through all requested extra fields. If custom scoping logic is define
234
+ for that field, run it. Otherwise, do nothing.</p>
235
+
236
+
237
+ </div>
238
+ </div>
239
+ <div class="tags">
240
+
241
+ <p class="tag_title">Returns:</p>
242
+ <ul class="return">
243
+
244
+ <li>
245
+
246
+
247
+ <span class='type'></span>
248
+
249
+
250
+
251
+
252
+ <div class='inline'>
253
+ <p>the scope object we are chaining/modofying</p>
254
+ </div>
255
+
256
+ </li>
257
+
258
+ </ul>
259
+
260
+ </div><table class="source_code">
261
+ <tr>
262
+ <td>
263
+ <pre class="lines">
264
+
265
+
266
+ 36
267
+ 37
268
+ 38
269
+ 39
270
+ 40
271
+ 41
272
+ 42</pre>
273
+ </td>
274
+ <td>
275
+ <pre class="code"><span class="info file"># File 'lib/jsonapi_compliable/scoping/extra_fields.rb', line 36</span>
276
+
277
+ <span class='kw'>def</span> <span class='id identifier rubyid_apply'>apply</span>
278
+ <span class='id identifier rubyid_each_extra_field'>each_extra_field</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_callable'>callable</span><span class='op'>|</span>
279
+ <span class='ivar'>@scope</span> <span class='op'>=</span> <span class='id identifier rubyid_callable'>callable</span><span class='period'>.</span><span class='id identifier rubyid_call'>call</span><span class='lparen'>(</span><span class='ivar'>@scope</span><span class='rparen'>)</span>
280
+ <span class='kw'>end</span>
281
+
282
+ <span class='ivar'>@scope</span>
283
+ <span class='kw'>end</span></pre>
284
+ </td>
285
+ </tr>
286
+ </table>
287
+ </div>
288
+
289
+ </div>
290
+
291
+ </div>
292
+
293
+ <div id="footer">
294
+ Generated on Fri May 5 15:53:23 2017 by
295
+ <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
296
+ 0.9.9 (ruby-2.3.0).
297
+ </div>
298
+
299
+ </div>
300
+ </body>
301
+ </html>