Class: Udb::Architecture

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

Direct Known Subclasses

ConfiguredArchitecture

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

Instance Method Summary collapse

Constructor Details

#initialize(arch_dir)

Parameters:

  • arch_dir (Pathname, String)

    Path to a directory with a fully merged/resolved architecture definition



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

#pathObject (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_versionsArray<ExtensionVersion>

Returns All known extension versions.

Returns:



208
209
210
# File 'lib/udb/architecture.rb', line 208

def extension_versions
  @extension_versions ||= extensions.map(&:versions).flatten.freeze
end

#objsArray<TopLevelDatabaseObject>

Returns All known objects.

Returns:



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?

Returns:

  • (PortfolioClass)

    Portfolio named name

  • (nil)

    if there is no Portfolio named name



256
257
258
# File 'lib/udb/architecture.rb', line 256

def portfolio(name)
  portfolio_hash[name]
end

#portfolio_class(name) ⇒ PortfolioClass?

Returns:

  • (PortfolioClass)

    Portfolio class named name

  • (nil)

    if there is no Portfolio class named name



234
# File 'lib/udb/architecture.rb', line 234

def portfolio_class(name) = portfolio_class_hash[name]

#portfolio_class_hashHash{String => PortfolioClass}

Returns Hash of all portfolio classes defined in the architecture.

Returns:

  • (Hash{String => PortfolioClass})

    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_classesArray<PortfolioClass>

Returns Alphabetical list of all portfolio classes defined in the architecture.

Returns:

  • (Array<PortfolioClass>)

    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_hashHash<String, Portfolio>

Returns Hash of all portfolios defined in the architecture.

Returns:

  • (Hash<String, Portfolio>)

    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

#portfoliosArray<Portfolio>

Returns Alphabetical list of all portfolios defined in the architecture.

Returns:

  • (Array<Portfolio>)

    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

Parameters:

  • uri (String)

Returns:

  • (T.untyped)

    The pointed-to object

Raises:

  • (ArgumentError)


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

Parameters:

  • resolver (Resolver)
  • show_progress (Boolean) (defaults to: true)

    Whether to show a progress bar



84
85
86
87
88
89
90
91
92
93
# File 'lib/udb/architecture.rb', line 84

def validate(resolver, show_progress: true)
  progressbar = ProgressBar.create(total: objs.size) if show_progress

  objs.each do |obj|
    next unless obj.is_a?(TopLevelDatabaseObject)

    progressbar.increment if show_progress
    obj.validate(resolver)
  end
end