railsful 0.1.0 → 0.1.1

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
  SHA256:
3
- metadata.gz: 77c58909e21f08d21955de91651f80db0b6e149351e2819e0980c8215f938fbb
4
- data.tar.gz: ad03136f8c07f8c9d8b7db6000f1aec732c91b2c3f450ec6446ed882b0f00884
3
+ metadata.gz: 579c6c21ef0b0e65a53d5449bb1ac7863670f20941a93e79d474eed2ca2d80b2
4
+ data.tar.gz: b9cb7322dfe0b08d636c481197ed2897ef021a1fa794165c0fc4631309e02d4a
5
5
  SHA512:
6
- metadata.gz: 1a8aab06a687afe8073b03541aa514e8e709983ea96b0f0e0802b08f93cabe4f3b71e70a465252b0b50e61288c1a300edda2433b9c2a7a2abae92d126a023696
7
- data.tar.gz: 99ac9e457415aee433f83f20e48e483dc8176f2b8a73a6fabcd52ce8d1232e069a65deb8b30a89f2fb3d12526409d5d3a32d036a3e84092cfa45cb84780bc90f
6
+ metadata.gz: 162cfe70d4b921ad3a8c9a3ec92161abf29e792bbc055583234f1e2570c5b84d2ee578012776a871e3898f3f89bfa36415a231956f6bbc4e944232f38d8ae4d5
7
+ data.tar.gz: 20ef9a433fe1594c3dd06912cf53ae8a0c5ac299dadc051e80fa46e262fbc99ecd60b0e3b70bb421ca8dbac7dd486bc58160833871ffa6ee73a2a075160a4b7b
data/.gitignore CHANGED
@@ -10,3 +10,5 @@ Gemfile.lock
10
10
 
11
11
  # rspec failure tracking
12
12
  .rspec_status
13
+
14
+ *.gem
@@ -1,8 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'deep_merge/rails_compat'
4
+ require 'active_support/inflector'
4
5
 
5
6
  module Railsful
7
+ # The deserializer class handles the "unwrapping" of incoming parameters.
8
+ # It translates jsonapi compliant params to those that Rails understands.
6
9
  class Deserializer
7
10
  attr_reader :params
8
11
 
@@ -43,11 +46,19 @@ module Railsful
43
46
  attrs = inc[:attributes]
44
47
 
45
48
  if params.dig(:data, :relationships, type, :data).is_a?(Array)
46
- # TODO: Pluralize the key here.
47
- included_hash["#{type}_attributes"] ||= []
48
- included_hash["#{type}_attributes"] << attrs
49
+ # We pluralize the type since we are dealing with a
50
+ # +has_many+ relationship.
51
+ plural = ActiveSupport::Inflector.pluralize(type)
52
+
53
+ included_hash["#{plural}_attributes"] ||= []
54
+ included_hash["#{plural}_attributes"] << attrs
49
55
  else
50
- included_hash["#{type}_attributes"] = attrs
56
+ # When the data value is not an Array we are assuming that we
57
+ # deal with a +has_one+ association. To be on the safe side we also
58
+ # call singularize on the type.
59
+ singular = ActiveSupport::Inflector.singularize(type)
60
+
61
+ included_hash["#{singular}_attributes"] = attrs
51
62
  end
52
63
  end
53
64
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Railsful
4
- VERSION = '0.1.0'.freeze
4
+ VERSION = '0.1.1'.freeze
5
5
  end
data/railsful.gemspec CHANGED
@@ -10,9 +10,9 @@ Gem::Specification.new do |spec|
10
10
  'marcus.geissler@hausgold.de']
11
11
 
12
12
  spec.summary = 'JSON API serializer and deserializer for Rails'
13
- spec.description = 'This gem provides useful helper functions to interact' \
14
- 'with JSON API.'
15
- spec.homepage = 'https://github.com/hausgold/restful'
13
+ spec.description = 'This gem provides useful helper functions to ' \
14
+ 'interaact with JSON API.'
15
+ spec.homepage = 'https://github.com/hausgold/railsful'
16
16
  spec.license = 'MIT'
17
17
 
18
18
  if spec.respond_to?(:metadata)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: railsful
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henning Vogt
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2019-01-14 00:00:00.000000000 Z
12
+ date: 2019-01-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: deep_merge
@@ -121,7 +121,7 @@ dependencies:
121
121
  - - "~>"
122
122
  - !ruby/object:Gem::Version
123
123
  version: '0.15'
124
- description: This gem provides useful helper functions to interactwith JSON API.
124
+ description: This gem provides useful helper functions to interaact with JSON API.
125
125
  email:
126
126
  - henning.vogt@hausgold.de
127
127
  - marcus.geissler@hausgold.de
@@ -152,7 +152,7 @@ files:
152
152
  - lib/railsful/serializer.rb
153
153
  - lib/railsful/version.rb
154
154
  - railsful.gemspec
155
- homepage: https://github.com/hausgold/restful
155
+ homepage: https://github.com/hausgold/railsful
156
156
  licenses:
157
157
  - MIT
158
158
  metadata: