lib/jsonapi/routing_ext.rb in jsonapi-resources-0.6.0 vs lib/jsonapi/routing_ext.rb in jsonapi-resources-0.6.1

- old
+ new

@@ -78,10 +78,16 @@ options[:except] << :edit unless options[:except].include?(:edit) || options[:except].include?('edit') else options[:except] = [:new, :edit] end + if res._immutable + options[:except] << :create + options[:except] << :update + options[:except] << :destroy + end + resources @resource_type, options do @scope[:jsonapi_resource] = @resource_type if block_given? yield @@ -115,18 +121,20 @@ if methods.include?(:show) match "relationships/#{formatted_relationship_name}", controller: options[:controller], action: 'show_relationship', relationship: link_type.to_s, via: [:get] end - if methods.include?(:update) - match "relationships/#{formatted_relationship_name}", controller: options[:controller], - action: 'update_relationship', relationship: link_type.to_s, via: [:put, :patch] - end + if res.mutable? + if methods.include?(:update) + match "relationships/#{formatted_relationship_name}", controller: options[:controller], + action: 'update_relationship', relationship: link_type.to_s, via: [:put, :patch] + end - if methods.include?(:destroy) - match "relationships/#{formatted_relationship_name}", controller: options[:controller], - action: 'destroy_relationship', relationship: link_type.to_s, via: [:delete] + if methods.include?(:destroy) + match "relationships/#{formatted_relationship_name}", controller: options[:controller], + action: 'destroy_relationship', relationship: link_type.to_s, via: [:delete] + end end end def jsonapi_links(*links) link_type = links.first @@ -141,22 +149,24 @@ if methods.include?(:show) match "relationships/#{formatted_relationship_name}", controller: options[:controller], action: 'show_relationship', relationship: link_type.to_s, via: [:get] end - if methods.include?(:create) - match "relationships/#{formatted_relationship_name}", controller: options[:controller], - action: 'create_relationship', relationship: link_type.to_s, via: [:post] - end + if res.mutable? + if methods.include?(:create) + match "relationships/#{formatted_relationship_name}", controller: options[:controller], + action: 'create_relationship', relationship: link_type.to_s, via: [:post] + end - if methods.include?(:update) - match "relationships/#{formatted_relationship_name}", controller: options[:controller], - action: 'update_relationship', relationship: link_type.to_s, via: [:put, :patch] - end + if methods.include?(:update) + match "relationships/#{formatted_relationship_name}", controller: options[:controller], + action: 'update_relationship', relationship: link_type.to_s, via: [:put, :patch] + end - if methods.include?(:destroy) - match "relationships/#{formatted_relationship_name}", controller: options[:controller], - action: 'destroy_relationship', relationship: link_type.to_s, via: [:delete] + if methods.include?(:destroy) + match "relationships/#{formatted_relationship_name}", controller: options[:controller], + action: 'destroy_relationship', relationship: link_type.to_s, via: [:delete] + end end end def jsonapi_related_resource(*relationship) source = JSONAPI::Resource.resource_for(resource_type_with_module_prefix)