json_api_params 0.2.1 → 0.2.2
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 +4 -4
- data/.travis.yml +10 -1
- data/Gemfile +5 -0
- data/README.md +2 -0
- data/lib/json_api_params.rb +15 -11
- data/lib/json_api_params/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f9c60ce18a999f9a93d59d5d1f36b5923d7b2ba
|
4
|
+
data.tar.gz: 42ea32834bd93acb481166c062a2fafdd9b3cf31
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 667312ef3cec8c9904218edb8080a8dc610b9070efe8b487902156302c0f1f85c29cf6b9f3c0f1d2d0933c06d8d307c00e57090c81013c5b119bfcab561c06c7
|
7
|
+
data.tar.gz: ac8f878b0b1224608b04b0840bcb18fd7f4ed23f41e972b587a89f713da99341ca4eaa36b4b89f49985cafa08e913d6d928f7df31c9ec417d40e243f7056e6b2
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# JsonApiParams
|
2
2
|
|
3
|
+
[](https://travis-ci.org/ursm/json_api_params) [](https://badge.fury.io/rb/json_api_params)
|
4
|
+
|
3
5
|
Extracts JSON API (http://jsonapi.org/) params to old-fashioned way.
|
4
6
|
|
5
7
|
## Installation
|
data/lib/json_api_params.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# XXX Though these are necessary, AC::Parameters doesn't require it
|
2
2
|
require 'active_support/core_ext/class/attribute_accessors'
|
3
|
+
require 'active_support/core_ext/module/delegation'
|
3
4
|
require 'date'
|
4
5
|
require 'rack/test/uploaded_file'
|
5
6
|
|
6
7
|
require 'action_controller/metal/strong_parameters'
|
7
|
-
require 'active_support/core_ext/object/try'
|
8
8
|
require 'active_support/core_ext/string/inflections'
|
9
9
|
|
10
10
|
class ActionController::Parameters
|
@@ -16,23 +16,27 @@ class ActionController::Parameters
|
|
16
16
|
}
|
17
17
|
end
|
18
18
|
|
19
|
-
relationships = data.fetch(:relationships) { self.class.new }
|
20
|
-
|
21
|
-
attributes = self.class[*data.fetch(:attributes) { Hash.new }.flat_map {|key, value|
|
19
|
+
relationships = data.fetch(:relationships) { self.class.new }.to_unsafe_hash.map {|key, value|
|
22
20
|
[key.underscore, value]
|
23
|
-
}
|
21
|
+
}.to_h
|
24
22
|
|
25
|
-
|
26
|
-
|
23
|
+
attributes = data.fetch(:attributes) { self.class.new }.to_unsafe_hash.map {|key, value|
|
24
|
+
[key.underscore, value]
|
25
|
+
}.to_h
|
27
26
|
|
28
|
-
|
27
|
+
extracted = relationships.each_with_object(attributes) {|(key, value), attrs|
|
28
|
+
case _data = value.fetch('data')
|
29
29
|
when Array
|
30
|
-
attrs["#{
|
31
|
-
item.fetch(
|
30
|
+
attrs["#{key}_ids"] = _data.map {|item|
|
31
|
+
item.fetch('id')
|
32
32
|
}
|
33
|
+
when nil
|
34
|
+
attrs["#{key}_id"] = nil
|
33
35
|
else
|
34
|
-
attrs["#{
|
36
|
+
attrs["#{key}_id"] = _data.fetch('id')
|
35
37
|
end
|
36
38
|
}
|
39
|
+
|
40
|
+
self.class.new(extracted)
|
37
41
|
end
|
38
42
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json_api_params
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Keita Urashima
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-06-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -132,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
132
132
|
version: '0'
|
133
133
|
requirements: []
|
134
134
|
rubyforge_project:
|
135
|
-
rubygems_version: 2.
|
135
|
+
rubygems_version: 2.5.1
|
136
136
|
signing_key:
|
137
137
|
specification_version: 4
|
138
138
|
summary: Extracts JSON API params to the old-fashioned way
|