jsonapi-resources 0.9.10 → 0.9.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jsonapi/link_builder.rb +13 -10
- data/lib/jsonapi/resource.rb +7 -3
- data/lib/jsonapi/resource_serializer.rb +15 -11
- data/lib/jsonapi/resources/version.rb +1 -1
- metadata +19 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb4334bc31d044c34bc94da87c16e9e3aa91b9289b18bd13690ae2f3ff179f56
|
4
|
+
data.tar.gz: 621418ce69f3d7de1d5874f0fcc85549cd80ea5d9798ed610a92571d126773da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6dff4f41d1dcb5452bddb882de80519a393e0e74f09aab94f1b0afc334c609603ffe3edfab252fdfcdfb859d8a053000bda275fd98d483bab88ca58cce9441a1
|
7
|
+
data.tar.gz: 4a19057381f81e6699dc689fc34331bac63df876ff3033d33f38ddbba9cf09aeecf0eaa09eb7a762cad489b7242f94985a76175ab92399ced5f45774d43bc18a
|
data/lib/jsonapi/link_builder.rb
CHANGED
@@ -105,16 +105,19 @@ module JSONAPI
|
|
105
105
|
end
|
106
106
|
|
107
107
|
def formatted_module_path_from_class(klass)
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
108
|
+
@_module_path_cache ||= {}
|
109
|
+
@_module_path_cache[klass] ||= begin
|
110
|
+
scopes = if @engine
|
111
|
+
module_scopes_from_class(klass)[1..-1]
|
112
|
+
else
|
113
|
+
module_scopes_from_class(klass)
|
114
|
+
end
|
115
|
+
|
116
|
+
unless scopes.empty?
|
117
|
+
"/#{ scopes.map {|scope| format_route(scope.to_s.underscore)}.compact.join('/') }/"
|
118
|
+
else
|
119
|
+
"/"
|
120
|
+
end
|
118
121
|
end
|
119
122
|
end
|
120
123
|
|
data/lib/jsonapi/resource.rb
CHANGED
@@ -5,6 +5,9 @@ module JSONAPI
|
|
5
5
|
class Resource
|
6
6
|
include Callbacks
|
7
7
|
|
8
|
+
DEFAULT_ATTRIBUTE_OPTIONS = { format: :default }.freeze
|
9
|
+
MODULE_PATH_REGEXP = /::[^:]+\Z/.freeze
|
10
|
+
|
8
11
|
attr_reader :context
|
9
12
|
|
10
13
|
define_jsonapi_resources_callbacks :create,
|
@@ -555,7 +558,7 @@ module JSONAPI
|
|
555
558
|
end
|
556
559
|
|
557
560
|
def default_attribute_options
|
558
|
-
|
561
|
+
DEFAULT_ATTRIBUTE_OPTIONS
|
559
562
|
end
|
560
563
|
|
561
564
|
def relationship(*attrs)
|
@@ -1133,7 +1136,7 @@ module JSONAPI
|
|
1133
1136
|
if name == 'JSONAPI::Resource'
|
1134
1137
|
''
|
1135
1138
|
else
|
1136
|
-
name =~
|
1139
|
+
name =~ MODULE_PATH_REGEXP ? ($`.freeze.gsub('::', '/') + '/').underscore : ''
|
1137
1140
|
end
|
1138
1141
|
end
|
1139
1142
|
|
@@ -1351,7 +1354,8 @@ module JSONAPI
|
|
1351
1354
|
rel_id = row[index+1]
|
1352
1355
|
assoc_rels = res.preloaded_fragments[rel_name]
|
1353
1356
|
if index == path.length - 1
|
1354
|
-
|
1357
|
+
association_res = target_resources[klass.name].fetch(rel_id, nil)
|
1358
|
+
assoc_rels[rel_id] = association_res if association_res
|
1355
1359
|
else
|
1356
1360
|
res = assoc_rels[rel_id]
|
1357
1361
|
end
|
@@ -287,7 +287,6 @@ module JSONAPI
|
|
287
287
|
include_linkage = ia && ia[:include]
|
288
288
|
include_linked_children = ia && !ia[:include_related].empty?
|
289
289
|
|
290
|
-
options = { filters: ia && ia[:include_filters] || {} }
|
291
290
|
if field_set.include?(name)
|
292
291
|
ro = relationship_object(source, relationship, include_linkage)
|
293
292
|
hash[format_key(name)] = ro unless ro.blank?
|
@@ -300,6 +299,7 @@ module JSONAPI
|
|
300
299
|
resources = if source.preloaded_fragments.has_key?(format_key(name))
|
301
300
|
source.preloaded_fragments[format_key(name)].values
|
302
301
|
else
|
302
|
+
options = { filters: ia && ia[:include_filters] || {} }
|
303
303
|
[source.public_send(name, options)].flatten(1).compact
|
304
304
|
end
|
305
305
|
resources.each do |resource|
|
@@ -468,16 +468,20 @@ module JSONAPI
|
|
468
468
|
|
469
469
|
# Extracts the foreign key value for a to_one relationship.
|
470
470
|
def foreign_key_value(source, relationship)
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
source.
|
478
|
-
|
479
|
-
|
480
|
-
|
471
|
+
# If you have changed the key_name, don't even try to look at `"#{relationship.name}_id"`
|
472
|
+
# just load the association and call the custom key_name
|
473
|
+
foreign_key_type_changed = relationship.options[:foreign_key_type_changed] || false
|
474
|
+
related_resource_id =
|
475
|
+
if source.preloaded_fragments.has_key?(format_key(relationship.name))
|
476
|
+
source.preloaded_fragments[format_key(relationship.name)].values.first.try(:id)
|
477
|
+
elsif !foreign_key_type_changed && source.respond_to?("#{relationship.name}_id")
|
478
|
+
# If you have direct access to the underlying id, you don't have to load the relationship
|
479
|
+
# which can save quite a lot of time when loading a lot of data.
|
480
|
+
# This does not apply to e.g. has_one :through relationships.
|
481
|
+
source.public_send("#{relationship.name}_id")
|
482
|
+
else
|
483
|
+
source.public_send(relationship.name).try(:id)
|
484
|
+
end
|
481
485
|
return nil unless related_resource_id
|
482
486
|
@id_formatter.format(related_resource_id)
|
483
487
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsonapi-resources
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Gebhardt
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2019-
|
12
|
+
date: 2019-12-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -17,14 +17,14 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version:
|
20
|
+
version: 1.17.3
|
21
21
|
type: :development
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version:
|
27
|
+
version: 1.17.3
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: rake
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -123,6 +123,20 @@ dependencies:
|
|
123
123
|
- - ">="
|
124
124
|
- !ruby/object:Gem::Version
|
125
125
|
version: '0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: memory_profiler
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
type: :development
|
134
|
+
prerelease: false
|
135
|
+
version_requirements: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
126
140
|
- !ruby/object:Gem::Dependency
|
127
141
|
name: activerecord
|
128
142
|
requirement: !ruby/object:Gem::Requirement
|
@@ -230,8 +244,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
230
244
|
- !ruby/object:Gem::Version
|
231
245
|
version: '0'
|
232
246
|
requirements: []
|
233
|
-
|
234
|
-
rubygems_version: 2.7.6
|
247
|
+
rubygems_version: 3.0.3
|
235
248
|
signing_key:
|
236
249
|
specification_version: 4
|
237
250
|
summary: Easily support JSON API in Rails.
|