Skip to content

Commit

Permalink
Merge pull request ManageIQ#1096 from kbrock/condense_send
Browse files Browse the repository at this point in the history
Remove unnecessary send
  • Loading branch information
Fryguy authored Nov 8, 2021
2 parents c94e822 + 9867870 commit bcce288
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions app/controllers/api/base_controller/manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ module Api
class BaseController
module Manager
def update_collection(type, id)
if @req.method == :put || @req.method == :patch
return send("#{@req.method}_resource", type, id)
case @req.method
when :put
return edit_resource(type, id, @req.json_body)
when :patch
return patch_resource(type, id)
end

unless id || @req.subcollection? || @req.json_body.key?("resources")
Expand All @@ -17,9 +20,9 @@ def update_collection(type, id)
"Unimplemented Action #{action} for #{type} resources" unless respond_to?(target)

if id
get_and_update_one_collection(@req.subcollection?, target, type, id)
update_one_collection(@req.subcollection?, target, type, id, @req.resource)
else
get_and_update_multiple_collections(@req.subcollection?, target, type)
update_multiple_collections(@req.subcollection?, target, type, @req.resources)
end
end

Expand All @@ -32,10 +35,6 @@ def collection_class(type)
@collection_klasses[type.to_sym] || collection_config.klass(type)
end

def put_resource(type, id)
edit_resource(type, id, @req.json_body)
end

#
# Patching a resource, post syntax
#
Expand Down Expand Up @@ -93,14 +92,6 @@ def target_resource_method(type, action)
end
end

def get_and_update_one_collection(is_subcollection, target, type, id)
update_one_collection(is_subcollection, target, type, id, @req.resource)
end

def get_and_update_multiple_collections(is_subcollection, target, type)
update_multiple_collections(is_subcollection, target, type, @req.resources)
end

def update_one_collection(is_subcollection, target, type, id, resource)
id = id.to_i if id.kind_of?(String) && id =~ /\A\d+\z/
parent_resource = parent_resource_obj if is_subcollection
Expand Down

0 comments on commit bcce288

Please sign in to comment.