Class: CFA::MultiFileConfig
- Inherits:
-
Object
- Object
- CFA::MultiFileConfig
- Includes:
- Yast::Logger
- Defined in:
- library/general/src/lib/cfa/multi_file_config.rb
Overview
API to handle configuration of services that are split between /usr/etc + /etc directories
This class is intended to work as base to implement support for that kind of configuration. It abstracts the details about which files are read/written, precedence, etc.
Individual files are handled through a separate class (usually CFA based).
Direct Known Subclasses
Class Attribute Summary collapse
-
.file_class ⇒ Object
Returns the value of attribute file_class.
-
.file_name ⇒ String
Base file name (like 'login.defs' or 'sysctl.conf').
-
.yast_file_name ⇒ String
YaST specific configuration file name (like '70-yast.conf').
Class Method Summary collapse
-
.define_attr(attr) ⇒ Object
Define an attribute.
-
.load ⇒ MultiFileConfig
Instantiates and loads configuration.
Instance Method Summary collapse
-
#conflicts ⇒ Array<Symbol>
Returns the conflicting attributes.
-
#load ⇒ Object
Loads the configuration.
-
#save ⇒ Object
Save changes to the YaST specific file.
Class Attribute Details
.file_class ⇒ Object
Returns the value of attribute file_class.
84 85 86 |
# File 'library/general/src/lib/cfa/multi_file_config.rb', line 84 def file_class @file_class end |
.file_name ⇒ String
Returns Base file name (like 'login.defs' or 'sysctl.conf').
76 77 78 |
# File 'library/general/src/lib/cfa/multi_file_config.rb', line 76 def file_name @file_name end |
.yast_file_name ⇒ String
Returns YaST specific configuration file name (like '70-yast.conf').
80 81 82 |
# File 'library/general/src/lib/cfa/multi_file_config.rb', line 80 def yast_file_name @yast_file_name end |
Class Method Details
.define_attr(attr) ⇒ Object
Define an attribute
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'library/general/src/lib/cfa/multi_file_config.rb', line 61 def define_attr(attr) define_method attr do file = files.reverse.find { |f| f.present?(attr) } return file.public_send(attr) if file yast_config_file.public_send(attr) end define_method "#{attr}=" do |value| yast_config_file.public_send("#{attr}=", value) end end |
.load ⇒ MultiFileConfig
Instantiates and loads configuration
Convenience method to create instance and load the configuration in just one call.
54 55 56 |
# File 'library/general/src/lib/cfa/multi_file_config.rb', line 54 def load new.tap(&:load) end |
Instance Method Details
#conflicts ⇒ Array<Symbol>
Returns the conflicting attributes
Conflicting attributes are the ones which override some value from the YaST specific configuration file.
117 118 119 120 121 |
# File 'library/general/src/lib/cfa/multi_file_config.rb', line 117 def conflicts higher_precedence_files.each_with_object([]) do |file, attrs| attrs.concat(yast_config_file.conflicts(file)) end end |
#load ⇒ Object
Loads the configuration
101 102 103 |
# File 'library/general/src/lib/cfa/multi_file_config.rb', line 101 def load files.each(&:load) end |
#save ⇒ Object
Save changes to the YaST specific file
106 107 108 109 |
# File 'library/general/src/lib/cfa/multi_file_config.rb', line 106 def save log_conflicts yast_config_file.save end |