Class: Udb::AbstractConfig
- Inherits:
-
Object
- Object
- Udb::AbstractConfig
- Extended by:
- T::Helpers, T::Sig
- Defined in:
- lib/udb/config.rb
Overview
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
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
-
#info ⇒ Object
readonly
Returns the value of attribute info.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #arch_overlay ⇒ Object
- #arch_overlay_abs ⇒ Object
- #compatible ⇒ Object
- #configured? ⇒ Boolean
- #description ⇒ Object
- #fully_configured? ⇒ Boolean
-
#initialize(data, info) ⇒ AbstractConfig
constructor
A new instance of AbstractConfig.
- #mxlen ⇒ Object
- #name ⇒ Object
- #overlay? ⇒ Boolean
- #param_values ⇒ Object
- #partially_configured? ⇒ Boolean
- #unconfigured? ⇒ Boolean
Constructor Details
#initialize(data, info) ⇒ AbstractConfig
Returns a new instance of AbstractConfig.
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
#info ⇒ Object (readonly)
Returns the value of attribute info.
61 62 63 |
# File 'lib/udb/config.rb', line 61 def info @info end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
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) ⇒ Object
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) ⇒ Object
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_overlay ⇒ Object
51 |
# File 'lib/udb/config.rb', line 51 def = @data["arch_overlay"] |
#arch_overlay_abs ⇒ Object
56 57 58 |
# File 'lib/udb/config.rb', line 56 def @info. end |
#compatible ⇒ Object
67 |
# File 'lib/udb/config.rb', line 67 def compatible = @data["compatible"] |
#configured? ⇒ Boolean
105 |
# File 'lib/udb/config.rb', line 105 def configured? = !unconfigured? |
#description ⇒ Object
64 |
# File 'lib/udb/config.rb', line 64 def description = @data["description"] |
#fully_configured? ⇒ Boolean
73 |
# File 'lib/udb/config.rb', line 73 def fully_configured?; end |
#mxlen ⇒ Object
70 |
# File 'lib/udb/config.rb', line 70 def mxlen; end |
#name ⇒ Object
102 |
# File 'lib/udb/config.rb', line 102 def name = @name |
#overlay? ⇒ Boolean
46 |
# File 'lib/udb/config.rb', line 46 def = !(@data["arch_overlay"].nil? || @data["arch_overlay"].empty?) |
#param_values ⇒ Object
42 |
# File 'lib/udb/config.rb', line 42 def param_values; end |
#partially_configured? ⇒ Boolean
76 |
# File 'lib/udb/config.rb', line 76 def partially_configured?; end |
#unconfigured? ⇒ Boolean
79 |
# File 'lib/udb/config.rb', line 79 def unconfigured?; end |