json_api_responders 2.1.0 → 2.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7d9223310e0bc824e94e72d5724cb531009adce1
4
- data.tar.gz: 3fca5112b3b31228a5a9a59772a341c203206bc2
3
+ metadata.gz: 1183871fbe98771c58abcc316bf0f38bdb631668
4
+ data.tar.gz: 454bfdb1b9172646beee12f2fae8f8b7407aa6d7
5
5
  SHA512:
6
- metadata.gz: f4bde721bbf3b652dc37157227cc5d50756ef87cb337c156b39a6d6c0b0d74007500494e4b10cc7f00086fba4eafadb6bae13bcdc108c999f1a05e10e7085487
7
- data.tar.gz: 42a5cd9abeecc0ffed50c3eb7e28e960d025c1289e62210c272a6127281bde6843ad1da9f6731bddfdf9b959551d0526acbdb6cc3b5534b5b1353931de31ea7f
6
+ metadata.gz: c5a94081106448d1522331b5ea27a66b8c9ccd5fdf99060f7943ca9f7e9a2b788826029b9c69ab506df77429901cc5da2db65bce5d7bf488ac73b759f7b18acc
7
+ data.tar.gz: 6cb309410bc083aa6084a179dae0fd8a8bbf839a55294ba163001f1ea5acd43eeba2a3e0e57c83fbd5b9f83830b7ca1637f0118abfc980369186289f73f128d0
data/README.md CHANGED
@@ -31,16 +31,21 @@ whatever can be passed to controller.render can be passed here:
31
31
  respond_with user, serializer: UserSerializer
32
32
 
33
33
  ## Configuration
34
- Currently you can only configure which options are required to be passed through the `respond_with` method. Bellow you can find an example:
34
+ Currently you can only configure which options are required to be passed through the `respond_with` method. These required options are categorized by the controller's actions. Bellow you can find an example:
35
35
 
36
36
  JsonApiResponders.configure do |config|
37
- config.required_options = [:foo]
37
+ config.required_options = {
38
+ index: [:each_serializer],
39
+ create: [:serializer]
40
+ }
38
41
  end
39
42
  ...
40
- user = User.first
41
- respond_with user, foo: :bar
43
+ def create
44
+ user = User.create(...)
45
+ respond_with user, serializer: UserSerializer
46
+ end
42
47
 
43
- If `:foo` was left out of the `respond_with` method you would see the `JsonApiResponders::Errors::RequiredOptionMissingError` be raised.
48
+ If `:serializer` was left out of the above `respond_with` method you would see the `JsonApiResponders::Errors::RequiredOptionMissingError` be raised.
44
49
 
45
50
  ## Responses
46
51
 
@@ -2,15 +2,32 @@ module JsonApiResponders
2
2
  class Config
3
3
  attr_reader :required_options
4
4
 
5
- def required_options=(opts = [])
5
+ def required_options=(opts = {})
6
6
  @required_options = opts
7
7
  end
8
8
 
9
9
  def check_required_options(options)
10
- return if @required_options.nil?
11
- @required_options.each do |key|
12
- raise JsonApiResponders::Errors::RequiredOptionMissingError, key unless options.key? key
10
+ return if @required_options.nil? || @required_options.empty?
11
+ action = action(options)
12
+
13
+ if action && @required_options.key?(action)
14
+ @required_options[action].each do |key|
15
+ raise JsonApiResponders::Errors::RequiredOptionMissingError, key unless options.key? key
16
+ end
13
17
  end
14
18
  end
19
+
20
+ private
21
+
22
+ def action(options)
23
+ options[:params][:action].to_sym if action_present?(options)
24
+ end
25
+
26
+ def action_present?(options)
27
+ !options[:params].nil? &&
28
+ !options[:params].empty? &&
29
+ !options[:params][:action].nil? &&
30
+ !options[:params][:action].empty?
31
+ end
15
32
  end
16
33
  end
@@ -18,7 +18,7 @@ module JsonApiResponders
18
18
  self.status ||= :created
19
19
  render_resource
20
20
  else
21
- self.status ||= :conflict
21
+ self.status ||= :unprocessable_entity
22
22
  render_error
23
23
  end
24
24
  end
@@ -28,7 +28,7 @@ module JsonApiResponders
28
28
  self.status ||= :ok
29
29
  render_resource
30
30
  else
31
- self.status ||= :conflict
31
+ self.status ||= :unprocessable_entity
32
32
  render_error
33
33
  end
34
34
  end
@@ -1,6 +1,6 @@
1
1
  module JsonApiResponders
2
2
  MAJOR = 2
3
3
  MINOR = 1
4
- PATCH = 0
4
+ PATCH = 3
5
5
  VERSION = [MAJOR, MINOR, PATCH].join('.').freeze
6
6
  end
@@ -31,15 +31,6 @@ module JsonApiResponders
31
31
  Responder.new(self, nil, on_error: { status: status, detail: detail }).respond_error
32
32
  end
33
33
 
34
- def deserialized_params
35
- @_deserialized_options ||=
36
- ActionController::Parameters.new(
37
- ActiveModelSerializers::Deserialization.jsonapi_parse(
38
- params, json_api_parse_options
39
- )
40
- )
41
- end
42
-
43
34
  private
44
35
 
45
36
  def record_not_found!
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_api_responders
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stanko Krtalić Rusendić