Skip to content
This repository was archived by the owner on Jun 2, 2021. It is now read-only.

Commit 48f3fd2

Browse files
committed
v3: Lower cyclomatic complexity in routes controller
Rubocop was not happy! Authored-by: Reid Mitchell <rmitchell@pivotal.io>
1 parent d5f625e commit 48f3fd2

1 file changed

Lines changed: 14 additions & 11 deletions

File tree

app/controllers/v3/routes_controller.rb

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,7 @@ def create
6767
unprocessable_space! unless space
6868
unprocessable_domain! unless domain
6969
unauthorized! unless permission_queryer.can_write_to_space?(space.guid)
70-
unprocessable_wildcard! if domain.shared? && message.wildcard? && !permission_queryer.can_write_globally?
71-
tcp_validation(message) if domain.protocols.include?('tcp')
72-
73-
if domain.router_group_guid && routing_api_client.router_group(domain.router_group_guid).nil?
74-
unprocessable!('Route could not be created because the specified domain does not have a valid router group.')
75-
end
70+
validate_domain_for_route_create!(domain, message)
7671

7772
route = RouteCreate.new(user_audit_info).create(message: message, space: space, domain: domain)
7873

@@ -241,6 +236,19 @@ def unprocessable_protocol_path!
241236
unprocessable!('Paths are not supported for TCP routes.')
242237
end
243238

239+
def validate_domain_for_route_create!(domain, message)
240+
unprocessable_wildcard! if domain.shared? && message.wildcard? && !permission_queryer.can_write_globally?
241+
242+
if domain.protocols.include?('tcp')
243+
unprocessable_protocol_host! if message.host
244+
unprocessable_protocol_path! if message.path
245+
end
246+
247+
if domain.router_group_guid && routing_api_client.router_group(domain.router_group_guid).nil?
248+
unprocessable!('Route could not be created because the specified domain does not have a valid router group.')
249+
end
250+
end
251+
244252
def validate_app_guids!(apps_hash, desired_app_guids)
245253
existing_app_guids = apps_hash.keys
246254

@@ -259,11 +267,6 @@ def app_not_found!
259267
resource_not_found!(:app)
260268
end
261269

262-
def tcp_validation(message)
263-
unprocessable_protocol_host! if message.host
264-
unprocessable_protocol_path! if message.path
265-
end
266-
267270
def routing_api_client
268271
@routing_api_client ||= CloudController::DependencyLocator.instance.routing_api_client
269272
end

0 commit comments

Comments
 (0)