Class: DInstaller::Config

Inherits:
Object
  • Object
show all
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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_data = nil) ⇒ Config

Constructor

Parameters:

  • config_data (Hash) (defaults to: nil)

    configuration data



61
62
63
# File 'lib/dinstaller/config.rb', line 61

def initialize(config_data = nil)
  @pure_data = config_data
end

Class Attribute Details

.baseObject

Returns the value of attribute base.



36
37
38
# File 'lib/dinstaller/config.rb', line 36

def base
  @base
end

.currentObject

Returns the value of attribute current.



36
37
38
# File 'lib/dinstaller/config.rb', line 36

def current
  @current
end

Instance Attribute Details

#pure_dataHash

Returns configuration data.

Returns:

  • (Hash)

    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

Parameters:

  • path (String|Pathname)

    File path



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

.resetObject

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

#copyConfig

Returns a copy of this Object

Returns:



97
98
99
# File 'lib/dinstaller/config.rb', line 97

def copy
  Marshal.load(Marshal.dump(self))
end

#dataObject



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

Returns:

  • (Config)

    new Configuration 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

Returns:

  • (Boolean)

    false if there is only one product; true otherwise



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