jsonapi.rb 1.4.3 → 1.4.4

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: '078a4013116a56347b75f38cb951c7856634e759'
4
- data.tar.gz: 880fbb7f75ccf7800c983a440c911011735318af
3
+ metadata.gz: 71f3acfa93d3beb62249295caf3eb1281bb3a26f
4
+ data.tar.gz: 55736764463a1fc310d5ec1a83d6f29dcb4c06ef
5
5
  SHA512:
6
- metadata.gz: 2c6cc8f62b6177ef07ccf875afeb25bd683328a6427a6f3178fdabdb0b737b94712c576fda1ad11c1813eea44bd63747134d77c7c18cd1e1123ea17c622c5fa5
7
- data.tar.gz: 64cd58a070442aeec8784885a0e6566c057e21e0445016f63c644d66c51c14942b1c5381ec5cdd3d155120849140cf183609b1130aee8f43ed57147bfcbf83b3
6
+ metadata.gz: 94ecad8c622c9d085b834855ab494eeffc25366c8ec107c74234e8874b5f3243635c6ac9f80b220fae689101735501c94c621fec6b5e3f82cf8f46a73a072f86
7
+ data.tar.gz: a0d360b993b759726a8f90ccefcca9d4ca2312a089a7d354fc96b1c8ac9bc722cbea507e8538f9a612aafd55c8bb83e9fefee07639500db11e52da96c4030e6f
@@ -0,0 +1,56 @@
1
+ workflow "Tests" {
2
+ on = "push"
3
+ resolves = [
4
+ "rspec-ruby2.3_rails4",
5
+ "rspec-ruby2.3_rails5",
6
+ "rspec-ruby2.6_rails4",
7
+ "rspec-ruby2.6_rails5"
8
+ ]
9
+ }
10
+
11
+ action "rspec-ruby2.3_rails4" {
12
+ uses = "docker://ruby:2.3-alpine"
13
+ env = {
14
+ RAILS_VERSION = "~> 4"
15
+ }
16
+ args = [
17
+ "sh", "-c",
18
+ "apk add -U git build-base sqlite-dev && rm Gemfile.lock && bundle install && rake"
19
+ ]
20
+ }
21
+
22
+ action "rspec-ruby2.3_rails5" {
23
+ uses = "docker://ruby:2.3-alpine"
24
+ needs = ["rspec-ruby2.3_rails4"]
25
+ env = {
26
+ RAILS_VERSION = "~> 5"
27
+ }
28
+ args = [
29
+ "sh", "-c",
30
+ "apk add -U git build-base sqlite-dev && rm Gemfile.lock && bundle install && rake"
31
+ ]
32
+ }
33
+
34
+ action "rspec-ruby2.6_rails4" {
35
+ uses = "docker://ruby:2.6-alpine"
36
+ needs = ["rspec-ruby2.3_rails5"]
37
+ env = {
38
+ RAILS_VERSION = "~> 4"
39
+ }
40
+ args = [
41
+ "sh", "-c",
42
+ "apk add -U git build-base sqlite-dev && rm Gemfile.lock && bundle install && rake"
43
+ ]
44
+ }
45
+
46
+ action "rspec-ruby2.6_rails5" {
47
+ uses = "docker://ruby:2.6-alpine"
48
+ needs = ["rspec-ruby2.6_rails4"]
49
+ env = {
50
+ RAILS_VERSION = "~> 5"
51
+ }
52
+ args = [
53
+ "sh", "-c",
54
+ "apk add -U git build-base sqlite-dev && rm Gemfile.lock && bundle install && rake"
55
+ ]
56
+ }
@@ -8,7 +8,7 @@ GIT
8
8
  PATH
9
9
  remote: .
10
10
  specs:
11
- jsonapi.rb (1.4.3)
11
+ jsonapi.rb (1.4.4)
12
12
  fast_jsonapi (~> 1.5)
13
13
  rack
14
14
  ransack
data/README.md CHANGED
@@ -67,6 +67,16 @@ Or install it yourself as:
67
67
 
68
68
  ## Usage
69
69
 
70
+ * [Object serialization](#object-serialization)
71
+ * [Collection meta](#collection-meta)
72
+ * [Error handling](#error-handling)
73
+ * [Includes and sparse fields](#includes-and-sparse-fields)
74
+ * [Filtering and sorting](#filtering-and-sorting)
75
+ * [Sorting using expressions](#sorting-using-expressions)
76
+ * [Pagination](#pagination)
77
+
78
+ ---
79
+
70
80
  To enable the support for Rails, add this to an initializer:
71
81
 
72
82
  ```ruby
@@ -79,7 +89,7 @@ JSONAPI::Rails.install!
79
89
  This will register the mime type and the `jsonapi` and `jsonapi_errors`
80
90
  renderers.
81
91
 
82
- ### Object Serialization
92
+ ### Object serialization
83
93
 
84
94
  The `jsonapi` renderer will try to guess and resolve the serializer class based
85
95
  on the object class, and if it is a collection, based on the first item in the
@@ -111,7 +121,26 @@ class CustomNamingController < ActionController::Base
111
121
  end
112
122
  ```
113
123
 
114
- #### Collection Meta
124
+ To provide extra parameters to the serializer,
125
+ implement the `jsonapi_serializer_params` method.
126
+
127
+ Here's an example:
128
+ ```ruby
129
+ class CustomSerializerParamsController < ActionController::Base
130
+
131
+ # ...
132
+
133
+ private
134
+
135
+ def jsonapi_serializer_params
136
+ {
137
+ first_name_upcase: params[:upcase].present?
138
+ }
139
+ end
140
+ end
141
+ ```
142
+
143
+ #### Collection meta
115
144
 
116
145
  To provide meta information for a collection, provide the `jsonapi_meta`
117
146
  controller method.
@@ -4,6 +4,14 @@ require 'jsonapi/active_model_error_serializer'
4
4
  # Rails integration
5
5
  module JSONAPI
6
6
  module Rails
7
+ JSONAPI_METHODS_MAPPING = {
8
+ meta: :jsonapi_meta,
9
+ links: :jsonapi_pagination,
10
+ fields: :jsonapi_fields,
11
+ include: :jsonapi_include,
12
+ params: :jsonapi_serializer_params
13
+ }
14
+
7
15
  # Updates the mime types and registers the renderers
8
16
  #
9
17
  # @return [NilClass]
@@ -71,11 +79,10 @@ module JSONAPI
71
79
  ActionController::Renderers.add(:jsonapi) do |resource, options|
72
80
  self.content_type ||= Mime[:jsonapi]
73
81
 
74
- options[:meta] ||= (
75
- jsonapi_meta(resource) if respond_to?(:jsonapi_meta, true))
76
- options[:links] ||= (
77
- jsonapi_pagination(resource) if respond_to?(:jsonapi_pagination, true)
78
- )
82
+ JSONAPI_METHODS_MAPPING.to_a[0..1].each do |opt, method_name|
83
+ next unless respond_to?(method_name, true)
84
+ options[opt] ||= send(method_name, resource)
85
+ end
79
86
 
80
87
  # If it's an empty collection, return it directly.
81
88
  many = JSONAPI::Rails.is_collection?(resource, options[:is_collection])
@@ -83,10 +90,9 @@ module JSONAPI
83
90
  return options.slice(:meta, :links).merge(data: []).to_json
84
91
  end
85
92
 
86
- options[:fields] ||= (
87
- jsonapi_fields if respond_to?(:jsonapi_fields, true))
88
- options[:include] ||= (
89
- jsonapi_include if respond_to?(:jsonapi_include, true))
93
+ JSONAPI_METHODS_MAPPING.to_a[2..-1].each do |opt, method_name|
94
+ options[opt] ||= send(method_name) if respond_to?(method_name, true)
95
+ end
90
96
 
91
97
  if respond_to?(:jsonapi_serializer_class, true)
92
98
  serializer_class = jsonapi_serializer_class(resource, many)
@@ -1,3 +1,3 @@
1
1
  module JSONAPI
2
- VERSION = '1.4.3'
2
+ VERSION = '1.4.4'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsonapi.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.3
4
+ version: 1.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stas Suscov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-22 00:00:00.000000000 Z
11
+ date: 2019-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fast_jsonapi
@@ -199,10 +199,10 @@ executables: []
199
199
  extensions: []
200
200
  extra_rdoc_files: []
201
201
  files:
202
+ - ".github/main.workflow"
202
203
  - ".gitignore"
203
204
  - ".rspec"
204
205
  - ".rubocop.yml"
205
- - ".travis.yml"
206
206
  - ".yardstick.yml"
207
207
  - Gemfile
208
208
  - Gemfile.lock
@@ -1,14 +0,0 @@
1
- ---
2
- sudo: false
3
- language: ruby
4
- cache: bundler
5
- rvm:
6
- - 2.6.1
7
- - 2.3.7
8
- env:
9
- - RAILS_VERSION='~> 5'
10
- - RAILS_VERSION='~> 4'
11
- before_install:
12
- - rm -f Gemfile.lock
13
- - gem uninstall -v '>= 2' -i $(rvm gemdir)@global -ax bundler || true
14
- - bundler --version || gem install bundler -v '< 2'