json_api_toolbox 0.16.2 → 0.17.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/json_api_toolbox.gemspec +3 -0
- data/lib/json_api_toolbox/paginable.rb +1 -1
- data/lib/json_api_toolbox/version.rb +1 -1
- data/lib/postable.rb +1 -0
- data/lib/renderizable.rb +17 -2
- data/lib/service.rb +1 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ad7345c4b37202ed05ab044fd99d6bfcd8e6e47
|
4
|
+
data.tar.gz: b742d7b754794c1ff35f586851562930cc8e068c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94985f43e75243383ef8e5a4e76f3187383a6a52079c005bba484c31df492b256ede3e6e48efae0df2c36bae76890b6d91fb4a29ef1b1cc9ea5534ec7a1aafc4
|
7
|
+
data.tar.gz: c782dffcd059fa36a99e4f1e49ec9af3182a9f642cd34769e76aa4421c556f37167efcaa860f3c860ad488f60ff93f89e4e588d417589cc59dc28f2c7650588a
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
|
5
5
|
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
|
+
|
9
|
+
## [0.17.0] - 2018-08-14
|
10
|
+
### Added
|
11
|
+
- Added support for `fields` parameter to renderizable according to jsonapi spec
|
12
|
+
|
8
13
|
## [0.16.2] - 2018-08-14
|
9
14
|
### Fixed
|
10
15
|
- Fixed broken JsonApiToolbox::Service
|
data/json_api_toolbox.gemspec
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# rubocop:disable Metrics/BlockLength
|
3
4
|
lib = File.expand_path('lib', __dir__)
|
4
5
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
6
|
require 'json_api_toolbox/version'
|
@@ -33,5 +34,7 @@ Gem::Specification.new do |spec|
|
|
33
34
|
spec.add_development_dependency 'pry'
|
34
35
|
spec.add_development_dependency 'pry-byebug'
|
35
36
|
spec.add_development_dependency 'rake'
|
37
|
+
spec.add_development_dependency 'rubocop'
|
36
38
|
spec.add_development_dependency 'shoulda-matchers', '~> 3.1'
|
37
39
|
end
|
40
|
+
# rubocop:enable Metrics/BlockLength
|
@@ -15,7 +15,7 @@ module JsonApiToolbox
|
|
15
15
|
def pagination(collection_resource)
|
16
16
|
{
|
17
17
|
first: 1,
|
18
|
-
last:
|
18
|
+
last: collection_resource.total_pages,
|
19
19
|
prev: collection_resource.previous_page,
|
20
20
|
next: collection_resource.next_page
|
21
21
|
}.reduce({}, &method(:page_links))
|
data/lib/postable.rb
CHANGED
data/lib/renderizable.rb
CHANGED
@@ -6,8 +6,9 @@ module JsonApiToolbox
|
|
6
6
|
if object.respond_to?(:errors) && object.errors.any?
|
7
7
|
render({ jsonapi_errors: object.errors }.merge(options))
|
8
8
|
else
|
9
|
-
renderization =
|
10
|
-
|
9
|
+
renderization = { jsonapi: object,
|
10
|
+
include: includes_params,
|
11
|
+
fields: fields }.merge(options)
|
11
12
|
render(build_meta_data(object).merge(renderization))
|
12
13
|
end
|
13
14
|
end
|
@@ -16,6 +17,14 @@ module JsonApiToolbox
|
|
16
17
|
params.fetch(:includes, {})
|
17
18
|
end
|
18
19
|
|
20
|
+
def fields
|
21
|
+
return {} unless fields?
|
22
|
+
|
23
|
+
params[:fields].permit!.to_h.map do |field, attributes|
|
24
|
+
[field, attributes.split(',')]
|
25
|
+
end.to_h
|
26
|
+
end
|
27
|
+
|
19
28
|
def permitted_params
|
20
29
|
model = controller_name.singularize
|
21
30
|
parsed_params = params.require(model).permit(permitted_attributes).to_h
|
@@ -46,6 +55,12 @@ module JsonApiToolbox
|
|
46
55
|
|
47
56
|
private
|
48
57
|
|
58
|
+
def fields?
|
59
|
+
params[:fields].present? &&
|
60
|
+
params[:fields].respond_to?(:permit!) &&
|
61
|
+
params[:fields].permit!.to_h.respond_to?(:map)
|
62
|
+
end
|
63
|
+
|
49
64
|
def model_name
|
50
65
|
controller_name.singularize.camelize.constantize
|
51
66
|
end
|
data/lib/service.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json_api_toolbox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.17.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adriano Bacha
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-11-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -206,6 +206,20 @@ dependencies:
|
|
206
206
|
- - ">="
|
207
207
|
- !ruby/object:Gem::Version
|
208
208
|
version: '0'
|
209
|
+
- !ruby/object:Gem::Dependency
|
210
|
+
name: rubocop
|
211
|
+
requirement: !ruby/object:Gem::Requirement
|
212
|
+
requirements:
|
213
|
+
- - ">="
|
214
|
+
- !ruby/object:Gem::Version
|
215
|
+
version: '0'
|
216
|
+
type: :development
|
217
|
+
prerelease: false
|
218
|
+
version_requirements: !ruby/object:Gem::Requirement
|
219
|
+
requirements:
|
220
|
+
- - ">="
|
221
|
+
- !ruby/object:Gem::Version
|
222
|
+
version: '0'
|
209
223
|
- !ruby/object:Gem::Dependency
|
210
224
|
name: shoulda-matchers
|
211
225
|
requirement: !ruby/object:Gem::Requirement
|