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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 952895eb529a1dc4a35696f7d464d1871b918441
4
- data.tar.gz: 1e69da16bb6c0ca606a302271aa6dd30e053a428
3
+ metadata.gz: 3ad7345c4b37202ed05ab044fd99d6bfcd8e6e47
4
+ data.tar.gz: b742d7b754794c1ff35f586851562930cc8e068c
5
5
  SHA512:
6
- metadata.gz: b81a6ff02235c5a963cc33adf63dbc3f02c6245febb7dd14e233ad27d13845b3a6c0a8f9a8b84dddd919a864e98a719c45e4ab04559a4283f769036846d7bda6
7
- data.tar.gz: 7e92686812ec7a3b3e092db09c9fc61ad9c0bfe56859b79fbdbd93870e01e979c4e3fe5110cb7efa6dbc791e74e6438c31802d0f7d76ad977a2430d11b003b88
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
@@ -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: collection_resource.total_pages,
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))
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JsonApiToolbox
4
- VERSION = '0.16.2'
4
+ VERSION = '0.17.0'
5
5
  end
data/lib/postable.rb CHANGED
@@ -21,6 +21,7 @@ module JsonApiToolbox
21
21
  association_i.name.to_s == key.to_s
22
22
  end
23
23
  return false unless association
24
+
24
25
  class_name = (association.options.symbolize_keys[:class_name] || key)
25
26
  ActiveSupport::Inflector.singularize(class_name).camelize.constantize
26
27
  end
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
- { jsonapi: object, include: includes_params }.merge(options)
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
@@ -17,6 +17,7 @@ module JsonApiToolbox
17
17
  def execute
18
18
  response = request
19
19
  return if response.code == 404
20
+
20
21
  Service.parse_response(response)
21
22
  end
22
23
 
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.16.2
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-08-22 00:00:00.000000000 Z
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