Skip to content

Commit

Permalink
Used symbols instead of an exception for control flow.
Browse files Browse the repository at this point in the history
  • Loading branch information
mvidner committed Dec 12, 2016
1 parent 6c7d7d2 commit 5d09e5c
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions src/lib/installation/select_system_role.rb
Expand Up @@ -26,9 +26,6 @@
Yast.import "ProductFeatures"

module Installation
# marker exception when additional dialog return abort
class AbortException < RuntimeError; end

class SelectSystemRole < ::UI::InstallationDialog
class << self
# once the user selects a role, remember it in case they come back
Expand All @@ -53,12 +50,13 @@ def run
end

if Yast::GetInstArgs.going_back
return :next if run_clients(self.class.original_role_id, going_back: true)
# If coming back, we have to run the additional dialogs first...
direction = run_clients(self.class.original_role_id, going_back: true)
# ... and only run the main dialog (super) if we are *still* going back
return direction unless direction == :back
end

super
rescue AbortException
return :abort
end

def dialog_title
Expand Down Expand Up @@ -100,31 +98,31 @@ def next_handler

apply_role(role_id)

# if run clients goes back, then show again this dialog
if !run_clients(role_id)
case run_clients(role_id)
when :next
super
when :back
# We show the main role dialog; but the additional clients have
# drawn over it, so do it again, and propagate its result.
finish_dialog(run)
return
when :abort
finish_dialog(:abort)
end

super

rescue AbortException
finish_dialog(:abort)
return
end

private

# @return true if clients successfully go to next dialog after roles
# @return [Symbol] what should the caller do next
# :next - go to next wizard dialog
# :back - show role selection dialog again
# :abort - user pressed Abort
def run_clients(role_id, going_back: false)
clients = raw_roles.find { |r| r["id"] == role_id }["additional_dialogs"]
clients ||= ""
clients = clients.split(",").map!(&:strip)

return !going_back if clients.empty?
result = going_back ? :back : :next
return result if clients.empty?

client_to_show = going_back ? clients.size - 1 : 0
loop do
Expand All @@ -145,7 +143,7 @@ def run_clients(role_id, going_back: false)
when :back
-1
when :abort
raise AbortException, "client aborted"
return :abort
else
raise "unsupported client response #{result.inspect}"
end
Expand All @@ -154,7 +152,7 @@ def run_clients(role_id, going_back: false)
break unless (0..(clients.size - 1)).cover?(client_to_show)
end

client_to_show >= clients.size
client_to_show >= clients.size ? :next : :back
end

def clear_role
Expand Down

0 comments on commit 5d09e5c

Please sign in to comment.