forest_liana 1.1.29 → 1.1.30
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/forest_liana/associations_controller.rb +2 -1
- data/app/deserializers/forest_liana/resource_deserializer.rb +5 -15
- data/app/serializers/forest_liana/serializer_factory.rb +16 -12
- data/app/services/forest_liana/resource_creator.rb +22 -0
- data/app/services/forest_liana/resource_updater.rb +23 -1
- data/app/services/forest_liana/schema_adapter.rb +1 -1
- data/lib/forest_liana/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8c61cca79d81e2d1d325eed17335c37ccd04347
|
4
|
+
data.tar.gz: 53171e4c8959338e211dfa666c79cc6e7a16aaaa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91828deca444c0822687ddce5f77b717647c08b4835d1c7678c1f9b1928cfd42916926142e43b6bff605585336693f9154a672a6283520bf3ed535d9a469ec68
|
7
|
+
data.tar.gz: 994e9efdc1f89a99004d89e226ae84d8616db81cab8ef7e7d0041a33308f1b7568d05300d981637ce249cadbaa50b74189cd279ff21afc88bc929dda694ea103
|
@@ -25,8 +25,9 @@ module ForestLiana
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def find_association
|
28
|
+
# Rails 3 wants a :sym argument.
|
28
29
|
@association = @resource.reflect_on_association(
|
29
|
-
params[:association_name])
|
30
|
+
params[:association_name].try(:to_sym))
|
30
31
|
|
31
32
|
# Only accept "many" associations
|
32
33
|
if @association.nil? ||
|
@@ -1,10 +1,9 @@
|
|
1
1
|
module ForestLiana
|
2
2
|
class ResourceDeserializer
|
3
3
|
|
4
|
-
def initialize(resource,
|
4
|
+
def initialize(resource, params)
|
5
5
|
@params = params
|
6
6
|
@resource = resource
|
7
|
-
@record = record
|
8
7
|
end
|
9
8
|
|
10
9
|
def perform
|
@@ -27,25 +26,16 @@ module ForestLiana
|
|
27
26
|
if @params['data']['relationships']
|
28
27
|
@params['data']['relationships'].each do |name, relationship|
|
29
28
|
data = relationship['data']
|
30
|
-
|
29
|
+
# Rails 3 requires a :sym argument for the reflect_on_association
|
30
|
+
# call.
|
31
|
+
association = @resource.reflect_on_association(name.try(:to_sym))
|
31
32
|
|
32
|
-
|
33
|
-
when :has_one, :belongs_to
|
33
|
+
if [:has_one, :belongs_to].include?(association.try(:macro))
|
34
34
|
if data.is_a?(Hash)
|
35
35
|
@attributes[name] = association.klass.find(data[:id])
|
36
36
|
elsif data.blank?
|
37
37
|
@attributes[name] = nil
|
38
38
|
end
|
39
|
-
when :has_many, :has_and_belongs_to_many
|
40
|
-
if data.is_a?(Array)
|
41
|
-
data.each do |x|
|
42
|
-
existing_records = @record.send(name)
|
43
|
-
new_record = association.klass.find(x[:id])
|
44
|
-
if !existing_records.include?(new_record)
|
45
|
-
existing_records << new_record
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
39
|
end
|
50
40
|
end
|
51
41
|
end
|
@@ -50,7 +50,7 @@ module ForestLiana
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def type
|
53
|
-
object.class.table_name.demodulize.
|
53
|
+
object.class.table_name.demodulize.dasherize
|
54
54
|
end
|
55
55
|
|
56
56
|
def format_name(attribute_name)
|
@@ -89,18 +89,22 @@ module ForestLiana
|
|
89
89
|
end
|
90
90
|
|
91
91
|
if ret[:href].blank?
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
if
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
92
|
+
begin
|
93
|
+
relationship_records = object.send(attribute_name)
|
94
|
+
|
95
|
+
if relationship_records.respond_to?(:each)
|
96
|
+
if Rails::VERSION::MAJOR == 4
|
97
|
+
ret[:href] = "/forest/#{object.class.table_name}/#{object.id}/#{attribute_name}"
|
98
|
+
ret[:meta] = { count: relationship_records.distinct.count }
|
99
|
+
else
|
100
|
+
ret[:href] = "/forest/#{object.class.table_name}/#{object.id}/#{attribute_name}"
|
101
|
+
ret[:meta] = {
|
102
|
+
count: relationship_records.count(:id, distinct: true)
|
103
|
+
}
|
104
|
+
end
|
103
105
|
end
|
106
|
+
rescue TypeError
|
107
|
+
puts "Cannot load the association #{attribute_name} on #{object.class.name} #{object.id}."
|
104
108
|
end
|
105
109
|
end
|
106
110
|
|
@@ -13,11 +13,33 @@ module ForestLiana
|
|
13
13
|
else
|
14
14
|
@record = @resource.create!(resource_params, without_protection: true)
|
15
15
|
end
|
16
|
+
|
17
|
+
set_has_many_relationships
|
16
18
|
end
|
17
19
|
|
18
20
|
def resource_params
|
19
21
|
ResourceDeserializer.new(@resource, @params[:resource]).perform
|
20
22
|
end
|
21
23
|
|
24
|
+
def set_has_many_relationships
|
25
|
+
if @params['data']['relationships']
|
26
|
+
@params['data']['relationships'].each do |name, relationship|
|
27
|
+
data = relationship['data']
|
28
|
+
association = @resource.reflect_on_association(name)
|
29
|
+
if [:has_many, :has_and_belongs_to_many].include?(
|
30
|
+
association.try(:macro))
|
31
|
+
if data.is_a?(Array)
|
32
|
+
data.each do |x|
|
33
|
+
existing_records = @record.send(name)
|
34
|
+
new_record = association.klass.find(x[:id])
|
35
|
+
if !existing_records.include?(new_record)
|
36
|
+
existing_records << new_record
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
22
44
|
end
|
23
45
|
end
|
@@ -15,11 +15,33 @@ module ForestLiana
|
|
15
15
|
else
|
16
16
|
@record.update_attributes!(resource_params, without_protection: true)
|
17
17
|
end
|
18
|
+
|
19
|
+
set_has_many_relationships
|
18
20
|
end
|
19
21
|
|
20
22
|
def resource_params
|
21
|
-
ResourceDeserializer.new(@resource, @
|
23
|
+
ResourceDeserializer.new(@resource, @params[:resource]).perform
|
22
24
|
end
|
23
25
|
|
26
|
+
def set_has_many_relationships
|
27
|
+
if @params['data']['relationships']
|
28
|
+
@params['data']['relationships'].each do |name, relationship|
|
29
|
+
data = relationship['data']
|
30
|
+
association = @resource.reflect_on_association(name)
|
31
|
+
if [:has_many, :has_and_belongs_to_many].include?(
|
32
|
+
association.try(:macro))
|
33
|
+
if data.is_a?(Array)
|
34
|
+
data.each do |x|
|
35
|
+
existing_records = @record.send(name)
|
36
|
+
new_record = association.klass.find(x[:id])
|
37
|
+
if !existing_records.include?(new_record)
|
38
|
+
existing_records << new_record
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
24
46
|
end
|
25
47
|
end
|
data/lib/forest_liana/version.rb
CHANGED
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.1.
|
4
|
+
version: 1.1.30
|
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-02-
|
11
|
+
date: 2016-02-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|