Class: Installation::SystemRole
- Inherits:
-
Object
- Object
- Installation::SystemRole
- Extended by:
- Forwardable
- Includes:
- Yast::Logger
- Defined in:
- src/lib/installation/system_role.rb
Overview
This class fetchs and stores the roles declared in the installation control file. It works as a storage for them and for the role selected during the installation.
Class Attribute Summary collapse
-
.current_role ⇒ SystemRole?
readonly
Returns the current role.
Instance Attribute Summary collapse
-
#description ⇒ String?
It descripts the main capabilities of the role and it is also usually translated because it is used for description and/or for help in some cases.
-
#id ⇒ String
This is the id or name of the role and used as reference to the role.
-
#label ⇒ String
The label is usually translated and shoule be a short word more descriptive than the id.
-
#order ⇒ Integer
readonly
Order of role.
Class Method Summary collapse
-
.all ⇒ Hash<String, SystemRole>
Returns an array with all the SystemRole objects sorted according to order.
-
.clear ⇒ Object
Clears roles cache.
-
.current ⇒ String?
Returns the current role id.
-
.default? ⇒ Boolean
returns if roles should set default or have no role preselected.
-
.find(role_id) ⇒ SystemRole?
Returns the SystemRole object for the specific role id.
-
.finish ⇒ Object
It runs a special finish handler for the current role if exists.
-
.from_control(raw_role) ⇒ SystemRole
Creates a SystemRole instance for the given role (in raw format).
-
.ids ⇒ Array<String>
Returns an array with all the role ids.
-
.raw_roles ⇒ Array<Hash>
Fetchs the roles from the control file and returns them as they are.
-
.select(role_id) ⇒ SystemRole
Establish as the current role the one given as parameter.
Instance Method Summary collapse
- #adapt_network ⇒ Object
-
#adapt_services ⇒ Array
Enables the role services defined in the control file.
-
#initialize(id:, order:, label: id, description: nil) ⇒ SystemRole
constructor
Constructor.
-
#overlay_features ⇒ Object
Overlays the product features for this role with the configuration obtained from the control file.
Constructor Details
#initialize(id:, order:, label: id, description: nil) ⇒ SystemRole
Constructor
Only the id, label and description are allowed to be initialized other options have to be set explicitly.
74 75 76 77 78 79 80 |
# File 'src/lib/installation/system_role.rb', line 74 def initialize(id:, order:, label: id, description: nil) @id = id @label = label @description = description @options = {} @order = order.to_i end |
Class Attribute Details
.current_role ⇒ SystemRole? (readonly)
Returns the current role
84 85 86 |
# File 'src/lib/installation/system_role.rb', line 84 def current_role @current_role end |
Instance Attribute Details
#description ⇒ String?
It descripts the main capabilities of the role and it is also usually translated because it is used for description and/or for help in some cases.
51 52 53 |
# File 'src/lib/installation/system_role.rb', line 51 def description @description end |
#id ⇒ String
This is the id or name of the role and used as reference to the role
40 41 42 |
# File 'src/lib/installation/system_role.rb', line 40 def id @id end |
#label ⇒ String
The label is usually translated and shoule be a short word more descriptive than the id.
45 46 47 |
# File 'src/lib/installation/system_role.rb', line 45 def label @label end |
#order ⇒ Integer (readonly)
Order of role.
55 56 57 |
# File 'src/lib/installation/system_role.rb', line 55 def order @order end |
Class Method Details
.all ⇒ Hash<String, SystemRole>
Returns an array with all the SystemRole objects sorted according to order
104 105 106 107 108 109 |
# File 'src/lib/installation/system_role.rb', line 104 def all return @roles if @roles @roles = raw_roles.map { |r| from_control(r) } @roles.sort_by!(&:order) end |
.clear ⇒ Object
Clears roles cache
112 113 114 |
# File 'src/lib/installation/system_role.rb', line 112 def clear @roles = nil end |
.current ⇒ String?
Returns the current role id
140 141 142 |
# File 'src/lib/installation/system_role.rb', line 140 def current @current_role ? @current_role.id : nil end |
.default? ⇒ Boolean
returns if roles should set default or have no role preselected
97 98 99 |
# File 'src/lib/installation/system_role.rb', line 97 def default? !all.first["no_default"] end |
.find(role_id) ⇒ SystemRole?
Returns the SystemRole object for the specific role id.
148 149 150 |
# File 'src/lib/installation/system_role.rb', line 148 def find(role_id) all.find { |r| r.id == role_id } end |
.finish ⇒ Object
It runs a special finish handler for the current role if exists
176 177 178 179 180 181 182 |
# File 'src/lib/installation/system_role.rb', line 176 def finish if !current log.info("There is no role selected so nothing to do") return end SystemRoleHandlersRunner.new.finish(current) end |
.from_control(raw_role) ⇒ SystemRole
Creates a SystemRole instance for the given role (in raw format).
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'src/lib/installation/system_role.rb', line 156 def from_control(raw_role) id = raw_role["id"] role = new( id: id, order: raw_role["order"], label: Yast::ProductControl.GetTranslatedText(id), description: Yast::ProductControl.GetTranslatedText("#{id}_description") ) role["additional_dialogs"] = raw_role["additional_dialogs"] role["services"] = raw_role["services"] || [] role["network"] = raw_role["network"] || {} role["no_default"] = raw_role["no_default"] || false role end |
.ids ⇒ Array<String>
Returns an array with all the role ids
92 93 94 |
# File 'src/lib/installation/system_role.rb', line 92 def ids all.map(&:id) end |
.raw_roles ⇒ Array<Hash>
Fetchs the roles from the control file and returns them as they are.
122 123 124 |
# File 'src/lib/installation/system_role.rb', line 122 def raw_roles Yast::ProductControl.system_roles end |
.select(role_id) ⇒ SystemRole
Establish as the current role the one given as parameter.
131 132 133 134 135 |
# File 'src/lib/installation/system_role.rb', line 131 def select(role_id) @current_role = find(role_id) log.info("Selected role: #{current}") current_role end |
Instance Method Details
#adapt_network ⇒ Object
215 216 217 218 219 220 221 |
# File 'src/lib/installation/system_role.rb', line 215 def adapt_network settings = Y2Network::ProposalSettings.instance network = Yast::ProductFeatures.GetSection("network") settings.modify_defaults(network.merge(self["network"] || {})) settings.apply_defaults end |
#adapt_services ⇒ Array
Enables the role services defined in the control file
188 189 190 191 192 193 194 |
# File 'src/lib/installation/system_role.rb', line 188 def adapt_services to_enable = (self["services"] || []).map { |s| s["name"] } log.info "enable for #{id} these services: #{to_enable.inspect}" Installation::Services.enabled = to_enable end |
#overlay_features ⇒ Object
Overlays the product features for this role with the configuration obtained from the control file
208 209 210 211 212 213 |
# File 'src/lib/installation/system_role.rb', line 208 def features = self.class.raw_roles.find { |r| r["id"] == id }.dup NON_OVERLAY_ATTRIBUTES.each { |a| features.delete(a) } Yast::ProductFeatures.SetOverlay(features) end |