json_api_params 0.2.1 → 0.2.2

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: 52862200b62f7fba69587fbf5b0fc50465e03696
4
- data.tar.gz: 79299c35029cc6c9e475d3d2ccf168b36ca57ce7
3
+ metadata.gz: 0f9c60ce18a999f9a93d59d5d1f36b5923d7b2ba
4
+ data.tar.gz: 42ea32834bd93acb481166c062a2fafdd9b3cf31
5
5
  SHA512:
6
- metadata.gz: 3f873e5ba02d5653b50e8054a5fcc3beb037cc0af75a7a863853460ac68418de6f5508bb00c130f51a1f8fe9e5adb283ab4942952724d34c026c7defc18d3d1e
7
- data.tar.gz: 99dc948684ceb0ed8c671a12d4112224761fe7ca9ad8137e51c1a3d7e9e617ba05c6aaf0974b614c88fe6edc6d821302c88d5ba5c6bcc4b421f2c8af7f709452
6
+ metadata.gz: 667312ef3cec8c9904218edb8080a8dc610b9070efe8b487902156302c0f1f85c29cf6b9f3c0f1d2d0933c06d8d307c00e57090c81013c5b119bfcab561c06c7
7
+ data.tar.gz: ac8f878b0b1224608b04b0840bcb18fd7f4ed23f41e972b587a89f713da99341ca4eaa36b4b89f49985cafa08e913d6d928f7df31c9ec417d40e243f7056e6b2
@@ -1,4 +1,13 @@
1
1
  language: ruby
2
+ sudo: false
3
+ cache:
4
+ - bundler
2
5
  rvm:
3
- - 2.2.3
6
+ - 2.2.5
7
+ - 2.3.1
4
8
  before_install: gem install bundler -v 1.10.6
9
+
10
+ env:
11
+ matrix:
12
+ - RAILS_VERSION="~> 4.2"
13
+ - RAILS_VERSION="~> 5.0.0.rc1"
data/Gemfile CHANGED
@@ -2,3 +2,8 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in json_api_params.gemspec
4
4
  gemspec
5
+
6
+ if ENV['RAILS_VERSION']
7
+ gem 'actionpack', ENV['RAILS_VERSION']
8
+ gem 'activesupport', ENV['RAILS_VERSION']
9
+ end
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # JsonApiParams
2
2
 
3
+ [![Build Status](https://travis-ci.org/ursm/json_api_params.svg?branch=master)](https://travis-ci.org/ursm/json_api_params) [![Gem Version](https://badge.fury.io/rb/json_api_params.svg)](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
@@ -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
- relationships.each_with_object(attributes) {|(key, value), attrs|
26
- k = key.underscore
23
+ attributes = data.fetch(:attributes) { self.class.new }.to_unsafe_hash.map {|key, value|
24
+ [key.underscore, value]
25
+ }.to_h
27
26
 
28
- case _data = value.fetch(:data)
27
+ extracted = relationships.each_with_object(attributes) {|(key, value), attrs|
28
+ case _data = value.fetch('data')
29
29
  when Array
30
- attrs["#{k}_ids"] = _data.map {|item|
31
- item.fetch(:id)
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["#{k}_id"] = _data.try(:fetch, :id)
36
+ attrs["#{key}_id"] = _data.fetch('id')
35
37
  end
36
38
  }
39
+
40
+ self.class.new(extracted)
37
41
  end
38
42
  end
@@ -1,3 +1,3 @@
1
1
  module JsonApiParams
2
- VERSION = '0.2.1'
2
+ VERSION = '0.2.2'
3
3
  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.1
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: 2015-10-11 00:00:00.000000000 Z
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.4.5.1
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