@@ -18,59 +18,58 @@ def format_route(route)
1818 end
1919
2020 def jsonapi_resource ( *resources , &block )
21- resource_type = resources . first
22- res = JSONAPI ::Resource . resource_for ( resource_type_with_module_prefix ( resources . first ) )
21+ @ resource_type = resources . first
22+ res = JSONAPI ::Resource . resource_for ( resource_type_with_module_prefix ( @resource_type ) )
2323
2424 options = resources . extract_options! . dup
25- options [ :controller ] ||= resource_type
25+ options [ :controller ] ||= @ resource_type
2626 options . merge! ( res . routing_resource_options )
27- options [ :path ] = format_route ( resource_type )
27+ options [ :path ] = format_route ( @ resource_type)
2828
29- resource resource_type , options do
30- @scope [ :jsonapi_resource ] = resource_type
29+ resource @ resource_type, options do
30+ @scope [ :jsonapi_resource ] = @ resource_type
3131
3232 if block_given?
3333 yield
3434 else
35- res . _associations . each do |association_name , association |
36- if association . is_a? ( JSONAPI ::Association ::HasMany )
37- jsonapi_links ( association_name )
38- else
39- jsonapi_link ( association_name )
40- end
41- end
35+ jsonapi_relationships
36+ end
37+ end
38+ end
39+
40+ def jsonapi_relationships
41+ res = JSONAPI ::Resource . resource_for ( resource_type_with_module_prefix ( @resource_type ) )
42+ res . _associations . each do |association_name , association |
43+ if association . is_a? ( JSONAPI ::Association ::HasMany )
44+ jsonapi_links ( association_name )
45+ jsonapi_related_resources ( association_name )
46+ else
47+ jsonapi_link ( association_name )
48+ jsonapi_related_resource ( association_name )
4249 end
4350 end
4451 end
4552
4653 def jsonapi_resources ( *resources , &block )
47- resource_type = resources . first
48- res = JSONAPI ::Resource . resource_for ( resource_type_with_module_prefix ( resources . first ) )
54+ @ resource_type = resources . first
55+ res = JSONAPI ::Resource . resource_for ( resource_type_with_module_prefix ( @resource_type ) )
4956
5057 options = resources . extract_options! . dup
51- options [ :controller ] ||= resource_type
58+ options [ :controller ] ||= @ resource_type
5259 options . merge! ( res . routing_resource_options )
5360
5461 # Route using the primary_key. Can be overridden using routing_resource_options
5562 options [ :param ] ||= res . _primary_key
5663
57- options [ :path ] = format_route ( resource_type )
64+ options [ :path ] = format_route ( @ resource_type)
5865
59- resources resource_type , options do
60- @scope [ :jsonapi_resource ] = resource_type
66+ resources @ resource_type, options do
67+ @scope [ :jsonapi_resource ] = @ resource_type
6168
6269 if block_given?
6370 yield
6471 else
65- res . _associations . each do |association_name , association |
66- if association . is_a? ( JSONAPI ::Association ::HasMany )
67- jsonapi_links ( association_name )
68- jsonapi_related_resources ( association_name )
69- else
70- jsonapi_link ( association_name )
71- jsonapi_related_resource ( association_name )
72- end
73- end
72+ jsonapi_relationships
7473 end
7574 end
7675 end
0 commit comments