forest_liana 1.3.41 → 1.3.42

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: f4dfed3e0970a565659ba855ce38ee4320217f6f
4
- data.tar.gz: a0986651eb37f09917c80304edf3e9b5fb0823c2
3
+ metadata.gz: cb3568d5560fd7e5f2bed09463aeabd25cdcf507
4
+ data.tar.gz: d08fed354b6e2ec24643975b1611df742f416307
5
5
  SHA512:
6
- metadata.gz: b71616c7680f9f2ff19657dde52fac62fb83b00b272a7a3c1308bd834a3335ae6c6c64cbc7e987aaea81f160e58aa818d1938852081cbf11f6a78594e925c241
7
- data.tar.gz: 6bac3c174f89e4be400cadc4399413309ba071f87208aa5599aab4c3bc6538b478716d6364bbfbd3e4632f1e67b84689f64d16eb85ee48b137ef5df7cc59bc3f
6
+ metadata.gz: 27ab72a652bc72f34efaff24b2853c0440879f86cf506f6cbd811fceba3b6f6d076d2b2a839501a0d5feef2b6eaebab478be8b0f2c5af3c26bad7dc28f96ebea
7
+ data.tar.gz: 630815abbb6a8ef6b6f2dc0510345fac00b65730afde352ae65507034ce5ceff98cb880ae9541a8ea768985cc0a73943b38730ec8fe8d7309552e3bba9be77be
@@ -59,7 +59,7 @@ module ForestLiana
59
59
  end
60
60
 
61
61
  def resource_params
62
- ResourceDeserializer.new(@resource, params[:resource]).perform
62
+ ResourceDeserializer.new(@resource, params[:resource], true).perform
63
63
  end
64
64
 
65
65
  def includes
@@ -58,7 +58,7 @@ module ForestLiana
58
58
  end
59
59
 
60
60
  def resource_params
61
- ResourceDeserializer.new(@resource, params[:resource]).perform
61
+ ResourceDeserializer.new(@resource, params[:resource], true).perform
62
62
  end
63
63
 
64
64
  def includes
@@ -3,13 +3,15 @@ require_relative '../../../lib/forest_liana/base64_string_io'
3
3
  module ForestLiana
4
4
  class ResourceDeserializer
5
5
 
6
- def initialize(resource, params)
6
+ def initialize(resource, params, with_relationships)
7
7
  @params = params.permit! if params.respond_to?(:permit!)
8
8
  @resource = resource
9
+ @with_relationships = with_relationships
9
10
  end
10
11
 
11
12
  def perform
12
13
  @attributes = extract_attributes
14
+ extract_relationships if @with_relationships
13
15
  extract_paperclip
14
16
  extract_carrierwave
15
17
  extract_acts_as_taggable
@@ -25,6 +27,37 @@ module ForestLiana
25
27
  end
26
28
  end
27
29
 
30
+ def extract_relationships
31
+ if @params['data']['relationships']
32
+ @params['data']['relationships'].each do |name, relationship|
33
+ data = relationship['data']
34
+ # Rails 3 requires a :sym argument for the reflect_on_association
35
+ # call.
36
+ association = @resource.reflect_on_association(name.try(:to_sym))
37
+
38
+ if [:has_one, :belongs_to].include?(association.try(:macro))
39
+ # TODO: refactor like this?
40
+ #if data.blank?
41
+ #@attributes[name] = nil
42
+ #else
43
+ #@attributes[name] = association.klass.find(data[:id])
44
+ #end
45
+
46
+ # ActionController::Parameters do not inherit from Hash anymore
47
+ # since Rails 5.
48
+ if (data.is_a?(Hash) || data.is_a?(ActionController::Parameters)) && data[:id]
49
+ @attributes[name] = association.klass.find(data[:id])
50
+ elsif data.blank?
51
+ @attributes[name] = nil
52
+ end
53
+ end
54
+ end
55
+
56
+ # Strong parameter permit all new relationships attributes.
57
+ @attributes = @attributes.permit! if @attributes.respond_to?(:permit!)
58
+ end
59
+ end
60
+
28
61
  def extract_paperclip
29
62
  return unless @resource.respond_to?(:attachment_definitions)
30
63
 
@@ -17,7 +17,7 @@ module ForestLiana
17
17
  end
18
18
 
19
19
  def resource_params
20
- ResourceDeserializer.new(@resource, @params[:resource]).perform
20
+ ResourceDeserializer.new(@resource, @params[:resource], true).perform
21
21
  end
22
22
 
23
23
  def set_has_many_relationships
@@ -18,7 +18,7 @@ module ForestLiana
18
18
  end
19
19
 
20
20
  def resource_params
21
- ResourceDeserializer.new(@resource, @params[:resource]).perform
21
+ ResourceDeserializer.new(@resource, @params[:resource], false).perform
22
22
  end
23
23
 
24
24
  def has_strong_parameter
@@ -1,3 +1,3 @@
1
1
  module ForestLiana
2
- VERSION = "1.3.41"
2
+ VERSION = "1.3.42"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: forest_liana
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.41
4
+ version: 1.3.42
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sandro Munda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-30 00:00:00.000000000 Z
11
+ date: 2016-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails