Class: Udb::Architecture
- Inherits:
-
Object
- Object
- Udb::Architecture
- Extended by:
- T::Sig
- Defined in:
- lib/udb/condition.rb,
lib/udb/architecture.rb
Direct Known Subclasses
Constant Summary collapse
- OBJS =
[ { fn_name: "extension", arch_dir: "ext", klass: Extension, kind: DatabaseObject::Kind::Extension }, { fn_name: "instruction", arch_dir: "inst", klass: Instruction, kind: DatabaseObject::Kind::Instruction }, { fn_name: "instruction_type", arch_dir: "inst_type", klass: InstructionType, kind: DatabaseObject::Kind::InstructionType }, { fn_name: "instruction_subtype", arch_dir: "inst_subtype", klass: InstructionSubtype, kind: DatabaseObject::Kind::InstructionSubtype }, { fn_name: "csr", arch_dir: "csr", klass: Csr, kind: DatabaseObject::Kind::Csr }, { fn_name: "param", arch_dir: "param", klass: Parameter, kind: DatabaseObject::Kind::Parameter }, { fn_name: "exception_code", arch_dir: "exception_code", klass: ExceptionCode, kind: DatabaseObject::Kind::ExceptionCode }, { fn_name: "interrupt_code", arch_dir: "interrupt_code", klass: InterruptCode, kind: DatabaseObject::Kind::InterruptCode }, { fn_name: "proc_cert_class", arch_dir: "proc_cert_class", klass: ProcCertClass, kind: DatabaseObject::Kind::ProcessorCertificateClass }, { fn_name: "proc_cert_model", arch_dir: "proc_cert_model", klass: ProcCertModel, kind: DatabaseObject::Kind::ProcessorCertificateModel }, { fn_name: "manual", arch_dir: "manual", klass: Manual, kind: DatabaseObject::Kind::Manual }, { fn_name: "manual_version", arch_dir: "manual_version", klass: ManualVersion, kind: DatabaseObject::Kind::ManualVersion }, { fn_name: "profile_release", arch_dir: "profile_release", klass: ProfileRelease, kind: DatabaseObject::Kind::ProfileRelease }, { fn_name: "profile_family", arch_dir: "profile_family", klass: ProfileFamily, kind: DatabaseObject::Kind::ProfileFamily }, { fn_name: "profile", arch_dir: "profile", klass: Profile, kind: DatabaseObject::Kind::Profile }, { fn_name: "prm", arch_dir: "prm", klass: Prm, kind: DatabaseObject::Kind::Prm } ].freeze
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Path to the directory with the standard YAML files.
Instance Method Summary collapse
-
#extension_versions ⇒ Array<ExtensionVersion>
All known extension versions.
- #initialize(arch_dir) constructor
-
#objs ⇒ Array<TopLevelDatabaseObject>
All known objects.
- #portfolio(name) ⇒ PortfolioClass?
- #portfolio_class(name) ⇒ PortfolioClass?
-
#portfolio_class_hash ⇒ Hash{String => PortfolioClass}
Hash of all portfolio classes defined in the architecture.
-
#portfolio_classes ⇒ Array<PortfolioClass>
Alphabetical list of all portfolio classes defined in the architecture.
-
#portfolio_hash ⇒ Hash<String, Portfolio>
Hash of all portfolios defined in the architecture.
-
#portfolios ⇒ Array<Portfolio>
Alphabetical list of all portfolios defined in the architecture.
-
#ref(uri) ⇒ T.untyped
given a ‘$ref` target, return the Ruby object.
-
#validate(resolver, show_progress: true)
validate the architecture against JSON Schema and any object-specific verification.
Constructor Details
#initialize(arch_dir)
71 72 73 74 75 76 77 78 79 |
# File 'lib/udb/architecture.rb', line 71 def initialize(arch_dir) @arch_dir = Pathname.new(arch_dir) raise "Arch directory not found: #{arch_dir}" unless @arch_dir.exist? @arch_dir = @arch_dir.realpath @path = @arch_dir # alias @objects = Concurrent::Hash.new @object_hashes = Concurrent::Hash.new end |
Instance Attribute Details
#path ⇒ Object (readonly)
Path to the directory with the standard YAML files
67 68 69 |
# File 'lib/udb/architecture.rb', line 67 def path @path end |
Instance Method Details
#extension_versions ⇒ Array<ExtensionVersion>
Returns All known extension versions.
208 209 210 |
# File 'lib/udb/architecture.rb', line 208 def extension_versions @extension_versions ||= extensions.map(&:versions).flatten.freeze end |
#objs ⇒ Array<TopLevelDatabaseObject>
Returns All known objects.
196 197 198 199 200 201 202 203 204 |
# File 'lib/udb/architecture.rb', line 196 def objs return @objs unless @objs.nil? @objs = [] OBJS.each do |obj_info| @objs.concat(send(ActiveSupport::Inflector.pluralize(obj_info[:fn_name]))) end @objs.freeze end |
#portfolio(name) ⇒ PortfolioClass?
256 257 258 |
# File 'lib/udb/architecture.rb', line 256 def portfolio(name) portfolio_hash[name] end |
#portfolio_class(name) ⇒ PortfolioClass?
234 |
# File 'lib/udb/architecture.rb', line 234 def portfolio_class(name) = portfolio_class_hash[name] |
#portfolio_class_hash ⇒ Hash{String => PortfolioClass}
Returns Hash of all portfolio classes defined in the architecture.
222 223 224 225 226 227 228 229 230 |
# File 'lib/udb/architecture.rb', line 222 def portfolio_class_hash return @portfolio_class_hash unless @portfolio_class_hash.nil? @portfolio_class_hash = {} portfolio_classes.each do |portfolio_class| @portfolio_class_hash[portfolio_class.name] = portfolio_class end @portfolio_class_hash.freeze end |
#portfolio_classes ⇒ Array<PortfolioClass>
Returns Alphabetical list of all portfolio classes defined in the architecture.
214 215 216 217 218 |
# File 'lib/udb/architecture.rb', line 214 def portfolio_classes return @portfolio_classes unless @portfolio_classes.nil? @portfolio_classes = profile_families.concat(proc_cert_classes).sort_by!(&:name).freeze end |
#portfolio_hash ⇒ Hash<String, Portfolio>
Returns Hash of all portfolios defined in the architecture.
244 245 246 247 248 249 250 251 252 |
# File 'lib/udb/architecture.rb', line 244 def portfolio_hash return @portfolio_hash unless @portfolio_hash.nil? @portfolio_hash = {} portfolios.each do |portfolio| @portfolio_hash[portfolio.name] = portfolio end @portfolio_hash end |
#portfolios ⇒ Array<Portfolio>
Returns Alphabetical list of all portfolios defined in the architecture.
237 238 239 240 241 |
# File 'lib/udb/architecture.rb', line 237 def portfolios return @portfolios unless @portfolios.nil? @portfolios = @profiles.concat(@certificates).sort_by!(&:name) end |
#ref(uri) ⇒ T.untyped
given a ‘$ref` target, return the Ruby object
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 |
# File 'lib/udb/architecture.rb', line 265 def ref(uri) raise ArgumentError, "JSON Reference (#{uri}) must contain one '#'" unless uri.count("#") == 1 file_path, obj_path = uri.split("#") file_path = T.must(file_path) obj = T.let(nil, T.untyped) obj = case file_path when /^proc_cert_class.*/ proc_cert_class_name = File.basename(file_path, ".yaml") proc_cert_class(proc_cert_class_name) when /^proc_cert_model.*/ proc_cert_model_name = File.basename(file_path, ".yaml") proc_cert_model(proc_cert_model_name) when /^csr.*/ csr_name = File.basename(file_path, ".yaml") csr(csr_name) when /^ext.*/ ext_name = File.basename(file_path, ".yaml") extension(ext_name) when %r{^inst/.*} inst_name = File.basename(file_path, ".yaml") instruction(inst_name) when /^manual.*/ manual_name = File.basename(file_path, ".yaml") manual(manual_name) when /^manual_version.*/ manual_name = File.basename(file_path, ".yaml") manual_version(manual_name) when /^profile_family.*/ profile_family_name = File.basename(file_path, ".yaml") profile_family(profile_family_name) when /^profile_release.*/ profile_release_name = File.basename(file_path, ".yaml") profile_release(profile_release_name) when /^profile.*/ profile_name = File.basename(file_path, ".yaml") profile(profile_name) when %r{^inst_subtype/.*/.*} inst_subtype_name = File.basename(file_path, ".yaml") instruction_subtype(inst_subtype_name) when %r{^inst_type/[^/]+} # type inst_type_name = File.basename(file_path, ".yaml") instruction_type(inst_type_name) else raise "Unhandled ref object: #{file_path}" end unless obj_path.nil? parts = obj_path.split("/") parts.each do |part| raise "Error in $ref. There is no method '#{part}' for a #{obj.class.name}" unless obj.respond_to?(part.to_sym) obj = obj.send(part) end end obj end |
#validate(resolver, show_progress: true)
This method returns an undefined value.
validate the architecture against JSON Schema and any object-specific verification
84 85 86 87 88 89 90 91 92 93 |
# File 'lib/udb/architecture.rb', line 84 def validate(resolver, show_progress: true) = ProgressBar.create(total: objs.size) if show_progress objs.each do |obj| next unless obj.is_a?(TopLevelDatabaseObject) .increment if show_progress obj.validate(resolver) end end |