json_apiable 0.2.0 → 0.2.1

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
  SHA256:
3
- metadata.gz: 02ceaeecfcdb306933da14c8f4596e355958a6bd6902dc37a365295e409d085e
4
- data.tar.gz: b5dc5338fcb3cd7fd1991f4dc18871ffdc3ed4d63c99d0e826469b558dba8dc0
3
+ metadata.gz: 2730ce86ac44faba4e0e0259559e346efe33442f474f9ba715aa2601045a02ac
4
+ data.tar.gz: f98a96c78028431660ac200e568b857133d581618594277a25829135a1a40cb1
5
5
  SHA512:
6
- metadata.gz: 5c5ddc873cee6e321ab133f8422d22dfe3cc2c46ae57af5c2a1bbfc9b759e00c50b333e11af758ef80f89c8f1b1a5edcbbbd8edb2dd79c13f4659ae20e8a5d4a
7
- data.tar.gz: 8e9cbdf0d269a0682b2f863b50fdcc71ed00a991174be19d293d75463578cada37390254d45d7a389b6447ece782d6c922b9bef79bc8d9518ede3bbbbf24188f
6
+ metadata.gz: 9646248670873df706251afa484cfc14cff8ac9f8fd3e3eea7465659b52fac3a1f4ffa5b5312ed3d4c570e3178d05354bb1d7991eaf7dbac3e27861bd510ec9b
7
+ data.tar.gz: 872d84af6b05e4396be7aece31fc8fff11c34690dc2f17cb5908b0d2c08d9cf9a2f06bc811e9de0e2b9a78e7edb9d12dd5c2a96365c46d95d1cb84bb5f5f1800
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- json_apiable (0.2.0)
4
+ json_apiable (0.2.1)
5
5
  activerecord (>= 4.2)
6
6
  activesupport (>= 4.2)
7
7
  fast_jsonapi (~> 1.5)
data/README.md CHANGED
@@ -150,10 +150,14 @@ JsonApiable.configure do |config|
150
150
  end
151
151
  ```
152
152
 
153
+ ### Gotchas
154
+ - To make sure requests with invalid attributes/relationships result in a well-structured json-api error, configure your Rails app to raise
155
+ exceptions on invalid parameters (JsonApiable will catch them and return an appropriate response). In `config/application.rb` set `config.action_controller.action_on_unpermitted_parameters = :raise`
156
+
153
157
  ### Limitations
154
- - `has_one` associations are currently not supported by `jsonapi_assign_params`. So if the updated resource
155
- contains an association whose foreign key exists in
156
- - complex attributes currently don't work
158
+ - `has_one` associations are expected to be represented as complex-attributes on the API level. So if User `has_one` Address,
159
+ than on the API level, JsonApiable expects address to be specified as a hash inside User's `attributes` rather than a separate relationship.
160
+ This makes sense in most cases. If your API represantion differs, `@post.update_attributes!(jsonapi_assign_params)` assignment won't work correctly.
157
161
 
158
162
  ## Development
159
163
 
@@ -24,18 +24,7 @@ module JsonApiable
24
24
  end
25
25
 
26
26
  def self.validate_data_params!(params, attributes, relationships)
27
- permitted = DataParams.build(params, attributes, relationships)
28
- unpermitted = params.dig(:data)&.keys.to_a - permitted&.keys.to_a
29
- raise ArgumentError, "Unpermitted member: #{unpermitted.first}" if unpermitted.present?
30
-
31
-
32
- unpermitted_arguments = params.dig(:data, :attributes)&.keys.to_a - permitted.dig(:attributes)&.keys.to_a
33
- raise ArgumentError, "Unpermitted attribute: #{unpermitted_arguments.first}" if unpermitted_arguments.present?
34
-
35
- unpermitted_relationships = params.dig(:data, :relationships)&.keys.to_a - permitted.dig(:relationships)&.keys.to_a
36
- raise ArgumentError, "Unpermitted relationship: #{unpermitted_relationships.first}" if unpermitted_relationships.present?
37
-
38
- permitted
27
+ DataParams.build(params, attributes, relationships)
39
28
  end
40
29
 
41
30
  def self.build_attributes_hash(attributes, excluded_attributes)
@@ -1,3 +1,3 @@
1
1
  module JsonApiable
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_apiable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Polischuk
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-01-13 00:00:00.000000000 Z
11
+ date: 2020-01-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord