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) }

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, info)

Parameters:



83
84
85
86
87
88
89
90
# File 'lib/udb/config.rb', line 83

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:



93
94
95
# File 'lib/udb/config.rb', line 93

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:



120
121
122
123
124
125
126
127
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
# File 'lib/udb/config.rb', line 120

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
    }
    data.fetch("params")["MXLEN"] = portfolio_grp.max_base
    freeze_data(data)
    PartialConfig.send(:new, data, info)
  else
    T.absurd(cfg_file_path_or_portfolio_grp)
  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

#configured?Boolean

Returns:

  • (Boolean)


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

def configured? = !unconfigured?

#fully_configured?Boolean

This method is abstract.

Returns:

  • (Boolean)


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

def fully_configured?; end

#mxlenInteger?

This method is abstract.

Returns:

  • (Integer, nil)


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

def mxlen; end

#nameString

Returns:

  • (String)


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

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)


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

def partially_configured?; end

#unconfigured?Boolean

This method is abstract.

Returns:

  • (Boolean)


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

def unconfigured?; end