Skip to content

Commit

Permalink
Refactor to satisfy code climate cognitive complexity
Browse files Browse the repository at this point in the history
  • Loading branch information
jvlcek committed Jan 30, 2019
1 parent 48f41f4 commit 45f2534
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions app/controllers/api/automate_domains_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,7 @@ class AutomateDomainsController < BaseController
def delete_resource(type, id = nil, _data = {})
raise BadRequestError, "Must specify an id for deleting a #{type} resource" unless id

api_action(type, id) do |klass|
domain = resource_search(id, type, klass)
api_log_info("Delete queued for #{automate_domain_ident(domain)}")

begin
# Only delete unlocked user domains. System or GIT based domains will not be deleted.
MiqAeDomain.where(:name => domain.name).each { |d| raise "Not deleting. Domain is locked." if d.contents_locked? }

MiqAeDomain.where(:name => domain.name).each(&:destroy_queue)
action_result(true, "Delete queued for #{automate_domain_ident(domain)}")
rescue => err
action_result(false, err.to_s)
end
end
delete_resource_action(type, id)
end

def refresh_from_source_resource(type, id = nil, data = nil)
Expand Down Expand Up @@ -48,6 +35,23 @@ def refresh_from_source_resource(type, id = nil, data = nil)

private

def delete_resource_action(type, id)
api_action(type, id) do |klass|
domain = resource_search(id, type, klass)
api_log_info("Delete will be queued for #{automate_domain_ident(domain)}")

begin
# Only delete unlocked user domains. System or GIT based domains will not be deleted.
MiqAeDomain.where(:name => domain.name).each { |d| raise "Not deleting. Domain is locked." if d.contents_locked? }

MiqAeDomain.where(:name => domain.name).each(&:destroy_queue)
action_result(true, "Delete queued for #{automate_domain_ident(domain)}")
rescue => err
action_result(false, err.to_s)
end
end
end

def automate_domain_ident(domain)
"Automate Domain id:#{domain.id} name:'#{domain.name}'"
end
Expand Down

0 comments on commit 45f2534

Please sign in to comment.