Skip to content

Commit cbca76e

Browse files
committed
Let jsonapi_resource recognize immutable
Currently, `create`, `update`, `destroy` routes are generated for resources that are marked as immutable. This change fixes that bug.
1 parent a973e14 commit cbca76e

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

lib/jsonapi/routing_ext.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ def jsonapi_resource(*resources, &_block)
3232
options[:except] = [:new, :edit]
3333
end
3434

35+
if res._immutable
36+
options[:except] << :create unless options[:except].include?(:create) || options[:except].include?('create')
37+
options[:except] << :update unless options[:except].include?(:update) || options[:except].include?('update')
38+
options[:except] << :destroy unless options[:except].include?(:destroy) || options[:except].include?('destroy')
39+
end
40+
3541
resource @resource_type, options do
3642
# :nocov:
3743
if @scope.respond_to? :[]=
@@ -96,9 +102,9 @@ def jsonapi_resources(*resources, &_block)
96102
end
97103

98104
if res._immutable
99-
options[:except] << :create
100-
options[:except] << :update
101-
options[:except] << :destroy
105+
options[:except] << :create unless options[:except].include?(:create) || options[:except].include?('create')
106+
options[:except] << :update unless options[:except].include?(:update) || options[:except].include?('update')
107+
options[:except] << :destroy unless options[:except].include?(:destroy) || options[:except].include?('destroy')
102108
end
103109

104110
resources @resource_type, options do

0 commit comments

Comments
 (0)