Skip to content

Commit 374b324

Browse files
authored
Merge pull request #828 from yawboakye/fix-jsonapi-resource-ignore-immutable
Let `jsonapi_resource` recognize immutable
2 parents a973e14 + cbca76e commit 374b324

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

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)