Class: DInstaller::Config
- Inherits:
-
Object
- Object
- DInstaller::Config
- Defined in:
- lib/dinstaller/config.rb
Overview
Class responsible for getting current configuration. It is smarter then just plain yaml reader as it also evaluates conditions in it, so it is result of all conditions in file. This also means that config needs to be re-evaluated if conditions data change, like if user pick different distro to install.
Class Attribute Summary collapse
-
.base ⇒ Object
Returns the value of attribute base.
-
.current ⇒ Object
Returns the value of attribute current.
Instance Attribute Summary collapse
-
#pure_data ⇒ Hash
Configuration data.
Class Method Summary collapse
-
.from_file(path) ⇒ Object
Load the configuration from a given file.
-
.load(logger = Logger.new($stdout)) ⇒ Object
Loads base and current config reading configuration from the system.
-
.reset ⇒ Object
It resets the configuration internal state.
Instance Method Summary collapse
-
#copy ⇒ Config
Returns a copy of this Object.
- #data ⇒ Object
-
#initialize(config_data = nil) ⇒ Config
constructor
Constructor.
-
#merge(config) ⇒ Config
Returns a new Config with the merge of the given ones.
-
#multi_product? ⇒ Boolean
Whether there are more than one product.
-
#parse_file(_arch = nil, _distro = nil) ⇒ Object
parse loaded yaml file, so it properly applies conditions with default options it load file without conditions.
- #pick_product(product) ⇒ Object
Constructor Details
#initialize(config_data = nil) ⇒ Config
Constructor
61 62 63 |
# File 'lib/dinstaller/config.rb', line 61 def initialize(config_data = nil) @pure_data = config_data end |
Class Attribute Details
.base ⇒ Object
Returns the value of attribute base.
36 37 38 |
# File 'lib/dinstaller/config.rb', line 36 def base @base end |
.current ⇒ Object
Returns the value of attribute current.
36 37 38 |
# File 'lib/dinstaller/config.rb', line 36 def current @current end |
Instance Attribute Details
#pure_data ⇒ Hash
Returns configuration data.
33 34 35 |
# File 'lib/dinstaller/config.rb', line 33 def pure_data @pure_data end |
Class Method Details
.from_file(path) ⇒ Object
Load the configuration from a given file
53 54 55 |
# File 'lib/dinstaller/config.rb', line 53 def from_file(path) new(YAML.safe_load(File.read(path.to_s))) end |
.load(logger = Logger.new($stdout)) ⇒ Object
Loads base and current config reading configuration from the system
39 40 41 42 |
# File 'lib/dinstaller/config.rb', line 39 def load(logger = Logger.new($stdout)) @base = ConfigReader.new(logger: logger).config @current = @base&.copy end |
.reset ⇒ Object
It resets the configuration internal state
45 46 47 48 |
# File 'lib/dinstaller/config.rb', line 45 def reset @base = nil @current = nil end |
Instance Method Details
#copy ⇒ Config
Returns a copy of this Object
97 98 99 |
# File 'lib/dinstaller/config.rb', line 97 def copy Marshal.load(Marshal.dump(self)) end |
#data ⇒ Object
75 76 77 78 79 80 81 |
# File 'lib/dinstaller/config.rb', line 75 def data return @data if @data @data = @pure_data.dup || {} pick_product(@data["products"].keys.first) if @data["products"] @data end |
#merge(config) ⇒ Config
Returns a new DInstaller::Config with the merge of the given ones
105 106 107 |
# File 'lib/dinstaller/config.rb', line 105 def merge(config) Config.new(simple_merge(data, config.data)) end |
#multi_product? ⇒ Boolean
Whether there are more than one product
90 91 92 |
# File 'lib/dinstaller/config.rb', line 90 def multi_product? data["products"].size > 1 end |
#parse_file(_arch = nil, _distro = nil) ⇒ Object
parse loaded yaml file, so it properly applies conditions with default options it load file without conditions
67 68 69 70 71 72 73 |
# File 'lib/dinstaller/config.rb', line 67 def parse_file(_arch = nil, _distro = nil) # TODO: move to internal only. public one should be something # like evaluate or just setter for distro and arch # logger.info "parse file with #{arch} and #{distro}" # TODO: do real evaluation of conditions data end |
#pick_product(product) ⇒ Object
83 84 85 |
# File 'lib/dinstaller/config.rb', line 83 def pick_product(product) data.merge!(data[product]) end |