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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 607d99c78950519019a9581a1de58a25019322af
4
- data.tar.gz: 0bec458c528b73b4ef7084db5b23ddd7e8e7add3
3
+ metadata.gz: cb9861ed5743d9c77ca4ce7e502002c46016ae82
4
+ data.tar.gz: e0239d8a635a3d7667759721653d698f2aa3aac8
5
5
  SHA512:
6
- metadata.gz: adb34843142599a98d7692d8783404fbbd4b6255455ad54606ba27a0069b3782e6e531ae50497052639e8d519bccd022b95215ffdb711d7e54f30a7a6c34a4dd
7
- data.tar.gz: 6e130efc4dcd29ad65635f965669c15efe71a1de76edb36f08437094e42a348c4b0817a4c6e542c16d7026ca2b99cbad21c4bc9a4a78392e72b5ee508ba6d1ad
6
+ metadata.gz: c263872e74e45cb4d8c88b389c7e50b628206162a71709848260a6a52442b81fe9f4088ef9b9d30a5edca46093aee996f18792b9e27cc1a461ef65ba167c79f6
7
+ data.tar.gz: 7e2a98858d1aa50679dd04fc7870790b5ea9ec40c44bf2c4f7578f414a9bca68bd0bca5262470e223bb0aa6bf88c2d9d04d8637a81d1de711ca5cba6d3e1a613
@@ -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
- "#{ base_path_name }_#{ end_path_name }_path"
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)
@@ -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[model_name.to_s.gsub('::', '/').underscore] = resource_type.to_s
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
- self: link_builder.self_link(source)
176
- }.merge(custom_links_hash(source)).compact
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
- linkage = {}
251
- linkage_id = foreign_key_value(source, relationship)
252
-
253
- if linkage_id
254
- linkage[:type] = format_key(relationship.type_for_source(source))
255
- linkage[:id] = linkage_id
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
- linkage.append({type: format_key(type), id: value})
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
@@ -1,5 +1,5 @@
1
1
  module JSONAPI
2
2
  module Resources
3
- VERSION = '0.8.0'
3
+ VERSION = '0.8.1'
4
4
  end
5
5
  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.0
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-09-15 00:00:00.000000000 Z
12
+ date: 2016-10-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler