Class: Udb::AbstractConfig Abstract

Inherits:
Object
  • Object
show all
Extended by:
T::Helpers, T::Sig
Defined in:
lib/udb/config.rb

Overview

This class is abstract.

It cannot be directly instantiated. Subclasses must implement the abstract methods below.

This class represents a configuration. Is is coded as an abstract base class (must be inherited by a child).

There are child classes derived from AbstractConfig to handle:

- Configurations specified by YAML files in the /cfg directory
- Configurations specified by portfolio groups (certificates and profile releases)

Direct Known Subclasses

FullConfig, PartialConfig, UnConfig

Constant Summary collapse

ParamValueType =
T.type_alias { T.any(Integer, String, T::Boolean, T::Array[Integer], T::Array[String], T::Array[T::Boolean]) }

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, info)

Parameters:



89
90
91
92
93
94
95
96
# File 'lib/udb/config.rb', line 89

def initialize(data, info)
  @data = data
  @info = info
  @name = @data.fetch("name")
  @name.freeze
  @type = ConfigType.deserialize(T.cast(@data.fetch("type"), String))
  @type.freeze
end

Instance Attribute Details

#infoResolver::ConfigInfo (readonly)



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

def info
  @info
end

#typeConfigType (readonly)

Returns:



99
100
101
# File 'lib/udb/config.rb', line 99

def type
  @type
end

Class Method Details

.create(cfg_file_path_or_portfolio_grp, info) ⇒ AbstractConfig

Factory method to create a FullConfig, PartialConfig, or UnConfig based on the contents of cfg_file_path_or_portfolio_grp

Parameters:

Returns:



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/udb/config.rb', line 128

def self.create(cfg_file_path_or_portfolio_grp, info)
  if cfg_file_path_or_portfolio_grp.is_a?(Pathname)
    cfg_file_path = T.cast(cfg_file_path_or_portfolio_grp, Pathname)
    raise ArgumentError, "Cannot find #{cfg_file_path}" unless cfg_file_path.exist?

    data = ::YAML.load_file(cfg_file_path)

    # now deep freeze the data
    freeze_data(data)

    case data["type"]
    when "fully configured"
      FullConfig.send(:new, data, info)
    when "partially configured"
      PartialConfig.send(:new, data, info)
    when "unconfigured"
      UnConfig.send(:new, data, info)
    else
      raise "Unexpected type (#{data['type']}) in config"
    end
  elsif cfg_file_path_or_portfolio_grp.is_a?(PortfolioGroup)
    portfolio_grp = T.cast(cfg_file_path_or_portfolio_grp, PortfolioGroup)
    data = {
      "$schema" => "config_schema.json#",
      "kind" => "architecture configuration",
      "type" => "partially configured",
      "name" => portfolio_grp.name,
      "description" => "Partial config construction from Portfolio Group #{portfolio_grp.name}",
      "params" => portfolio_grp.param_values,
      "mandatory_extensions" => portfolio_grp.mandatory_ext_reqs.map do |ext_req|
        {
          "name" => ext_req.name,
          "version" => ext_req.requirement_specs.map(&:to_s)
        }
      end
    }
    freeze_data(data)
    PartialConfig.send(:new, data, info)
  else
    T.absurd(cfg_file_path_or_portfolio_grp)
  end
end

.create_from_data(data, info) ⇒ AbstractConfig

Create an AbstractConfig directly from a config data hash, bypassing file I/O. Used when the config is already in memory (e.g., portfolio-derived temp configs).

Parameters:

Returns:



174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/udb/config.rb', line 174

def self.create_from_data(data, info)
  freeze_data(data)
  case data["type"]
  when "fully configured"
    FullConfig.send(:new, data, info)
  when "partially configured"
    PartialConfig.send(:new, data, info)
  when "unconfigured"
    UnConfig.send(:new, data, info)
  else
    raise "Unexpected type (#{data['type']}) in config"
  end
end

Instance Method Details

#arch_overlaynil, String

Returns:

  • (nil)

    No arch_overlay for this config

  • (String, nil)

    Either a path to an overlay directory, or the name of a folder under arch_overlay/



51
# File 'lib/udb/config.rb', line 51

def arch_overlay = @data["arch_overlay"]

#arch_overlay_absObject

Returns:

  • No arch_overlay for this config

  • (Pathname, nil)

    Absolute path to the arch_overlay



56
57
58
# File 'lib/udb/config.rb', line 56

def arch_overlay_abs
  @info.overlay_path
end

#compatibleString, ...

Returns:

  • (String, Array<String>, nil)


67
# File 'lib/udb/config.rb', line 67

def compatible = @data["compatible"]

#configured?Boolean

Returns:

  • (Boolean)


105
# File 'lib/udb/config.rb', line 105

def configured? = !unconfigured?

#descriptionString

Returns:

  • (String)


64
# File 'lib/udb/config.rb', line 64

def description = @data["description"]

#fully_configured?Boolean

This method is abstract.

Returns:

  • (Boolean)


73
# File 'lib/udb/config.rb', line 73

def fully_configured?; end

#mxlenInteger?

This method is abstract.

Returns:

  • (Integer, nil)


70
# File 'lib/udb/config.rb', line 70

def mxlen; end

#nameString

Returns:

  • (String)


102
# File 'lib/udb/config.rb', line 102

def name = @name

#overlay?Boolean

Returns Is an overlay present?.

Returns:

  • (Boolean)

    Is an overlay present?



46
# File 'lib/udb/config.rb', line 46

def overlay?  = !(@data["arch_overlay"].nil? || @data["arch_overlay"].empty?)

#param_valuesHash{String => ParamValueType}

This method is abstract.

Returns A hash mapping parameter name to value for any parameter that has been configured with a value. May be empty.

Returns:

  • (Hash{String => ParamValueType})

    A hash mapping parameter name to value for any parameter that has been configured with a value. May be empty.



42
# File 'lib/udb/config.rb', line 42

def param_values; end

#partially_configured?Boolean

This method is abstract.

Returns:

  • (Boolean)


76
# File 'lib/udb/config.rb', line 76

def partially_configured?; end

#unconfigured?Boolean

This method is abstract.

Returns:

  • (Boolean)


79
# File 'lib/udb/config.rb', line 79

def unconfigured?; end