Skip to content

Commit

Permalink
Improvements from code review
Browse files Browse the repository at this point in the history
- Yast.import at top level, like `require`
- Don't `include Yast`
- Less nesting
- Specify return value in a corner case
  • Loading branch information
mvidner committed Mar 7, 2016
1 parent e0df2d7 commit 8b9da6d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 29 deletions.
45 changes: 18 additions & 27 deletions src/lib/installation/select_system_role.rb
Expand Up @@ -18,17 +18,15 @@

require "yast"
require "ui/installation_dialog"
Yast.import "ProductControl"
Yast.import "ProductFeatures"

module Installation
class SelectSystemRole < ::UI::InstallationDialog
include Yast

def initialize
super

textdomain "installation"
Yast.import "ProductControl"
Yast.import "ProductFeatures"
end

def run
Expand All @@ -40,8 +38,6 @@ def run
super
end

public # called by parent class

def dialog_title
_("System Role")
end
Expand All @@ -51,32 +47,27 @@ def help_text
end

def dialog_content
RadioButtonGroup(
Id(:roles),
VBox(
* ui_roles.map do |r|
VBox(
Left(RadioButton(Id(r[:id]), r[:label])),
HBox(
ui_roles = role_attributes.each_with_object(VBox()) do |r, vbox|
vbox << Left(RadioButton(Id(r[:id]), r[:label]))
vbox << HBox(
HSpacing(4),
Left(Label(r[:description]))
),
VSpacing(2)
)
end
)
)
)
vbox << VSpacing(2)
end

RadioButtonGroup(Id(:roles), ui_roles)
end

def create_dialog
clear_role
ok = super
UI.ChangeWidget(Id(:roles), :CurrentButton, ui_roles.first[:id])
Yast::UI.ChangeWidget(Id(:roles), :CurrentButton, role_attributes.first[:id])
ok
end

def next_handler
role_id = UI.QueryWidget(Id(:roles), :CurrentButton)
role_id = Yast::UI.QueryWidget(Id(:roles), :CurrentButton)
apply_role(role_id)

super
Expand All @@ -85,15 +76,15 @@ def next_handler
private

def clear_role
ProductFeatures.ClearOverlay
Yast::ProductFeatures.ClearOverlay
end

def apply_role(role_id)
log.info "Applying system role '#{role_id}'"
features = raw_roles.find { |r| r["id"] == role_id }
features = features.dup
features.delete("id")
ProductFeatures.SetOverlay(features)
Yast::ProductFeatures.SetOverlay(features)
end

# the contents is an overlay for ProductFeatures sections
Expand All @@ -103,17 +94,17 @@ def apply_role(role_id)
# ]
# @return [Array<Hash{String => Object}>]
def raw_roles
ProductControl.productControl.fetch("system_roles", [])
Yast::ProductControl.productControl.fetch("system_roles", [])
end

def ui_roles
def role_attributes
raw_roles.map do |r|
id = r["id"]

{
id: id,
label: ProductControl.GetTranslatedText(id),
description: ProductControl.GetTranslatedText(id + "_description")
label: Yast::ProductControl.GetTranslatedText(id),
description: Yast::ProductControl.GetTranslatedText(id + "_description")
}
end
end
Expand Down
4 changes: 2 additions & 2 deletions test/select_system_role_test.rb
Expand Up @@ -23,9 +23,9 @@
.and_return("system_roles" => [])
end

it "does not display dialog" do
it "does not display dialog, and returns :auto" do
expect(Yast::Wizard).to_not receive(:SetContents)
subject.run
expect(subject.run).to eq(:auto)
end
end

Expand Down

0 comments on commit 8b9da6d

Please sign in to comment.