jsonapi-resources 0.8.0 → 0.8.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 +4 -4
- data/lib/jsonapi/link_builder.rb +6 -1
- data/lib/jsonapi/resource.rb +2 -2
- data/lib/jsonapi/resource_serializer.rb +12 -14
- data/lib/jsonapi/resources/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: cb9861ed5743d9c77ca4ce7e502002c46016ae82
|
4
|
+
data.tar.gz: e0239d8a635a3d7667759721653d698f2aa3aac8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c263872e74e45cb4d8c88b389c7e50b628206162a71709848260a6a52442b81fe9f4088ef9b9d30a5edca46093aee996f18792b9e27cc1a461ef65ba167c79f6
|
7
|
+
data.tar.gz: 7e2a98858d1aa50679dd04fc7870790b5ea9ec40c44bf2c4f7578f414a9bca68bd0bca5262470e223bb0aa6bf88c2d9d04d8637a81d1de711ca5cba6d3e1a613
|
data/lib/jsonapi/link_builder.rb
CHANGED
@@ -95,7 +95,12 @@ module JSONAPI
|
|
95
95
|
scopes = module_scopes_from_class(klass)[1..-1]
|
96
96
|
base_path_name = scopes.map { |scope| scope.underscore }.join("_")
|
97
97
|
end_path_name = klass._type.to_s
|
98
|
-
|
98
|
+
|
99
|
+
if base_path_name.blank?
|
100
|
+
"#{ end_path_name }_path"
|
101
|
+
else
|
102
|
+
"#{ base_path_name }_#{ end_path_name }_path"
|
103
|
+
end
|
99
104
|
end
|
100
105
|
|
101
106
|
def format_route(route)
|
data/lib/jsonapi/resource.rb
CHANGED
@@ -423,6 +423,7 @@ module JSONAPI
|
|
423
423
|
end
|
424
424
|
|
425
425
|
def resource_for(type)
|
426
|
+
type = type.underscore
|
426
427
|
type_with_module = type.include?('/') ? type : module_path + type
|
427
428
|
|
428
429
|
resource_name = _resource_name_from_type(type_with_module)
|
@@ -539,10 +540,9 @@ module JSONAPI
|
|
539
540
|
end
|
540
541
|
|
541
542
|
def model_hint(model: _model_name, resource: _type)
|
542
|
-
model_name = ((model.is_a?(Class)) && (model < ActiveRecord::Base)) ? model.name : model
|
543
543
|
resource_type = ((resource.is_a?(Class)) && (resource < JSONAPI::Resource)) ? resource._type : resource.to_s
|
544
544
|
|
545
|
-
_model_hints[
|
545
|
+
_model_hints[model.to_s.gsub('::', '/').underscore] = resource_type.to_s
|
546
546
|
end
|
547
547
|
|
548
548
|
def filters(*attrs)
|
@@ -171,9 +171,9 @@ module JSONAPI
|
|
171
171
|
end
|
172
172
|
|
173
173
|
def links_hash(source)
|
174
|
-
|
175
|
-
|
176
|
-
|
174
|
+
links = custom_links_hash(source)
|
175
|
+
links[:self] = link_builder.self_link(source) unless links.key?(:self)
|
176
|
+
links.compact
|
177
177
|
end
|
178
178
|
|
179
179
|
def custom_links_hash(source)
|
@@ -247,16 +247,12 @@ module JSONAPI
|
|
247
247
|
end
|
248
248
|
|
249
249
|
def to_one_linkage(source, relationship)
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
else
|
257
|
-
linkage = nil
|
258
|
-
end
|
259
|
-
linkage
|
250
|
+
return unless linkage_id = foreign_key_value(source, relationship)
|
251
|
+
return unless linkage_type = format_key(relationship.type_for_source(source))
|
252
|
+
{
|
253
|
+
type: linkage_type,
|
254
|
+
id: linkage_id,
|
255
|
+
}
|
260
256
|
end
|
261
257
|
|
262
258
|
def to_many_linkage(source, relationship)
|
@@ -264,7 +260,9 @@ module JSONAPI
|
|
264
260
|
linkage_types_and_values = foreign_key_types_and_values(source, relationship)
|
265
261
|
|
266
262
|
linkage_types_and_values.each do |type, value|
|
267
|
-
|
263
|
+
if type && value
|
264
|
+
linkage.append({type: format_key(type), id: @id_formatter.format(value)})
|
265
|
+
end
|
268
266
|
end
|
269
267
|
linkage
|
270
268
|
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.8.
|
4
|
+
version: 0.8.1
|
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: 2016-
|
12
|
+
date: 2016-10-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|