Class: Y2Network::AutoinstProfile::SectionWithAttributes
- Inherits:
-
Object
- Object
- Y2Network::AutoinstProfile::SectionWithAttributes
- Includes:
- Yast::Logger
- Defined in:
- src/lib/y2network/autoinst_profile/section_with_attributes.rb
Overview
This class is supposed to live in autoyast2 or yast2. When done, please, adapt yast2-storage-ng accordingly.
Abstract base class for some AutoYaST profile sections
Direct Known Subclasses
DNSSection, InterfaceSection, InterfacesSection, RouteSection, RoutingSection, S390DeviceSection, S390DevicesSection, UdevRuleSection, UdevRulesSection
Instance Attribute Summary collapse
-
#parent ⇒ #parent, #section_name
readonly
This value only makes sense when SectionWithAttributes.new_from_hashes is used.
Class Method Summary collapse
-
.attributes ⇒ Array<Hash>
Description of the attributes in the section.
-
.new_from_hashes(hash, parent = nil) ⇒ SectionWithAttributes
Creates an instance based on the profile representation used by the AutoYaST modules (nested arrays and hashes).
Instance Method Summary collapse
-
#init_from_hashes(hash) ⇒ Object
Method used by SectionWithAttributes.new_from_hashes to populate the attributes.
-
#initialize(parent = nil) ⇒ SectionWithAttributes
constructor
Constructor.
-
#section_name ⇒ String
Returns the section name.
-
#to_hashes ⇒ Hash
Content of the section in the format used by the AutoYaST modules (nested arrays and hashes).
Constructor Details
#initialize(parent = nil) ⇒ SectionWithAttributes
Constructor
83 84 85 |
# File 'src/lib/y2network/autoinst_profile/section_with_attributes.rb', line 83 def initialize(parent = nil) @parent = parent end |
Instance Attribute Details
#parent ⇒ #parent, #section_name (readonly)
This value only makes sense when new_from_hashes is used.
78 79 80 |
# File 'src/lib/y2network/autoinst_profile/section_with_attributes.rb', line 78 def parent @parent end |
Class Method Details
.attributes ⇒ Array<Hash>
Description of the attributes in the section.
To be defined by each subclass. Each entry contains a hash with the mandatory key :name and an optional key :xml_name; the values are symbols.
40 41 42 |
# File 'src/lib/y2network/autoinst_profile/section_with_attributes.rb', line 40 def attributes [] end |
.new_from_hashes(hash, parent = nil) ⇒ SectionWithAttributes
Creates an instance based on the profile representation used by the AutoYaST modules (nested arrays and hashes).
This method provides no extra validation, type conversion or initialization to default values. Those responsibilities belong to the AutoYaST modules. The hash is expected to be valid and contain the relevant information. Attributes are set to nil for missing keys and for blank values.
58 59 60 61 62 |
# File 'src/lib/y2network/autoinst_profile/section_with_attributes.rb', line 58 def new_from_hashes(hash, parent = nil) result = new(parent) result.init_from_hashes(hash) result end |
Instance Method Details
#init_from_hashes(hash) ⇒ Object
Method used by new_from_hashes to populate the attributes.
By default, it simply assigns the non-empty hash values to the corresponding attributes, logging unknown keys. The subclass is expected to refine this behavior if needed.
94 95 96 |
# File 'src/lib/y2network/autoinst_profile/section_with_attributes.rb', line 94 def init_from_hashes(hash) init_scalars_from_hash(hash) end |
#section_name ⇒ String
Returns the section name
In some cases, the section name does not match with the XML name and this method should be redefined.
124 125 126 127 128 129 |
# File 'src/lib/y2network/autoinst_profile/section_with_attributes.rb', line 124 def section_name klass_name = self.class.name.split("::").last klass_name .gsub(/([a-z])([A-Z])/, "\\1_\\2").downcase .chomp("_section") end |
#to_hashes ⇒ Hash
Content of the section in the format used by the AutoYaST modules (nested arrays and hashes).
104 105 106 107 108 109 110 111 112 |
# File 'src/lib/y2network/autoinst_profile/section_with_attributes.rb', line 104 def to_hashes attributes.each_with_object({}) do |attribute, result| value = attribute_value(attribute) next if attribute_skip?(value) key = attribute_key(attribute) result[key] = value end end |