snfoil-rails 0.4.4 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sn_foil/controller/api.rb +17 -6
- data/lib/sn_foil/controller/concerns/index_controller_concern.rb +1 -0
- data/lib/sn_foil/controller/concerns/setup_controller_concern.rb +3 -2
- data/lib/sn_foil/jsonapi_deserializer.rb +4 -2
- data/lib/sn_foil/rails/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 73e5f3f298f380d6961452b753e3d5ff22f35a4a466b99590cd2409a78ea339e
|
4
|
+
data.tar.gz: 2ce8432635e0d889791954955d984d7b81d2d99888dbcbd5ab728e98019eadc6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8767df32da2db2772c633123436bcef81a98f9fe2c37cc1739922e8f07543e0cb593a3fb0a126bc15bfa0cb9abd4f7a419a951c925413c54951e9f4f16b01d45
|
7
|
+
data.tar.gz: d2e717c282cf33e7f1a5dd7f42feffe0c1b726c472368d477837f1e64676b2f9dc933d71231c4de5d84f2eb55546c42001dc9bffdb912f26d4d029bf7e710658
|
@@ -40,27 +40,38 @@ module SnFoil
|
|
40
40
|
|
41
41
|
def render_change(model, **options)
|
42
42
|
if model.errors.empty?
|
43
|
-
|
43
|
+
params
|
44
|
+
render json: serializer(**options).new(model,
|
45
|
+
**options,
|
46
|
+
params: (options[:controller_params] || options[:params] || {})
|
47
|
+
.merge(current_entity: current_entity)).serializable_hash
|
44
48
|
else
|
45
|
-
render model.errors, status: :unprocessable_entity
|
49
|
+
render json: model.errors, status: :unprocessable_entity
|
46
50
|
end
|
47
51
|
end
|
48
52
|
|
49
53
|
def render_destroy(model, **_options)
|
50
54
|
if model.errors.empty?
|
51
|
-
render status: :no_content
|
55
|
+
render json: {}, status: :no_content
|
52
56
|
else
|
53
|
-
render model.errors, status: :unprocessable_entity
|
57
|
+
render json: model.errors, status: :unprocessable_entity
|
54
58
|
end
|
55
59
|
end
|
56
60
|
|
57
61
|
def render_index(results, **options)
|
58
|
-
render json: serializer(**options).new(paginate(results, **options),
|
62
|
+
render json: serializer(**options).new(paginate(results, **options),
|
63
|
+
**options,
|
64
|
+
params: (options[:controller_params] || options[:params] || {})
|
65
|
+
.merge(current_entity: current_entity),
|
66
|
+
meta: meta(results, **options))
|
59
67
|
.serializable_hash
|
60
68
|
end
|
61
69
|
|
62
70
|
def render_show(model, **options)
|
63
|
-
render json: serializer(**options).new(model,
|
71
|
+
render json: serializer(**options).new(model,
|
72
|
+
**options,
|
73
|
+
params: (options[:controller_params] || options[:params] || {})
|
74
|
+
.merge(current_entity: current_entity)).serializable_hash
|
64
75
|
end
|
65
76
|
|
66
77
|
private
|
@@ -28,7 +28,7 @@ module SnFoil
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def current_context(**options)
|
31
|
-
@current_context ||= context(**options).new(
|
31
|
+
@current_context ||= context(**options).new(context_entity)
|
32
32
|
end
|
33
33
|
|
34
34
|
protected
|
@@ -75,7 +75,8 @@ module SnFoil
|
|
75
75
|
options
|
76
76
|
end
|
77
77
|
|
78
|
-
def
|
78
|
+
def context_entity
|
79
|
+
return current_entity if defined? current_entity
|
79
80
|
return current_user if defined? current_user
|
80
81
|
end
|
81
82
|
end
|
@@ -77,7 +77,7 @@ module SnFoil
|
|
77
77
|
def data_id(attributes, data)
|
78
78
|
if data[:id]
|
79
79
|
attributes[:id] = data[:id]
|
80
|
-
elsif
|
80
|
+
elsif data[:'local:id']
|
81
81
|
attributes[:lid] = data[:'local:id']
|
82
82
|
end
|
83
83
|
attributes
|
@@ -117,6 +117,7 @@ module SnFoil
|
|
117
117
|
resource_data = data.dig(:relationships, key, :data)
|
118
118
|
return attributes unless resource_data
|
119
119
|
|
120
|
+
resource_data = data_id(resource_data, resource_data)
|
120
121
|
attribute_data = lookup_relationship(resource_data)
|
121
122
|
relationship_data = { data: attribute_data || resource_data }
|
122
123
|
attributes[opts.fetch(:key) { key }] = deserializer.new(relationship_data, **options, included: included).parse
|
@@ -128,6 +129,7 @@ module SnFoil
|
|
128
129
|
return attributes unless array_data
|
129
130
|
|
130
131
|
attributes[opts.fetch(:key) { key }] = array_data.map do |resource_data|
|
132
|
+
resource_data = data_id(resource_data, resource_data)
|
131
133
|
attribute_data = lookup_relationship(resource_data)
|
132
134
|
relationship_data = { data: attribute_data || resource_data }
|
133
135
|
deserializer.new(relationship_data, **options, included: included).parse
|
@@ -136,7 +138,7 @@ module SnFoil
|
|
136
138
|
end
|
137
139
|
|
138
140
|
def lookup_relationship(type:, id: nil, lid: nil, **_opts)
|
139
|
-
raise ::ArgumentError,
|
141
|
+
raise ::ArgumentError, "missing keyword: id or lid for type: #{type}" unless id || lid
|
140
142
|
|
141
143
|
included&.find do |x|
|
142
144
|
x[:type].eql?(type) &&
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: snfoil-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Howes
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2020-03
|
12
|
+
date: 2020-06-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -45,14 +45,14 @@ dependencies:
|
|
45
45
|
requirements:
|
46
46
|
- - "~>"
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version: '0.
|
48
|
+
version: '0.5'
|
49
49
|
type: :runtime
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
53
|
- - "~>"
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version: '0.
|
55
|
+
version: '0.5'
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
57
|
name: bundler
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|