Class: ExtensionVersion

Inherits:
Object
  • Object
show all
Defined in:
lib/arch_obj_models/extension.rb

Overview

A specific version of an extension

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, version, arch_def) ⇒ ExtensionVersion

Returns a new instance of ExtensionVersion.

Parameters:

  • name (#to_s)

    The extension name

  • version (Integer, String)

    The version specifier

  • arch_def (ArchDef)

    The architecture definition



297
298
299
300
301
302
303
304
305
306
307
308
# File 'lib/arch_obj_models/extension.rb', line 297

def initialize(name, version, arch_def)
  @name = name.to_s
  @version = Gem::Version.new(version)
  @arch_def = arch_def
  unless arch_def.nil?
    @ext = arch_def.extension(@name)
    raise "Extension #{name} not found in arch def" if @ext.nil?

    @data = @ext.data["versions"].find { |v| v["version"] == version.to_s }
    raise "Extension #{name} version #{version} not found in arch def" if @data.nil?
  end
end

Instance Attribute Details

#extExtension (readonly)

Returns Extension.

Returns:



292
293
294
# File 'lib/arch_obj_models/extension.rb', line 292

def ext
  @ext
end

#nameString (readonly)

Returns Name of the extension.

Returns:

  • (String)

    Name of the extension



286
287
288
# File 'lib/arch_obj_models/extension.rb', line 286

def name
  @name
end

#versionGem::Version (readonly)

Returns Version of the extension.

Returns:

  • (Gem::Version)

    Version of the extension



289
290
291
# File 'lib/arch_obj_models/extension.rb', line 289

def version
  @version
end

Instance Method Details

#<=>(other) ⇒ Object

sorts extension by name, then by version

Raises:

  • (ArgumentError)


409
410
411
412
413
414
415
416
417
# File 'lib/arch_obj_models/extension.rb', line 409

def <=>(other)
  raise ArgumentError, "ExtensionVersions are only comparable to other extension versions" unless other.is_a?(ExtensionVersion)

  if other.name != @name
    @name <=> other.name
  else
    @version <=> other.version
  end
end

#==(other) ⇒ Boolean #==(other) ⇒ Boolean

Overloads:

  • #==(other) ⇒ Boolean

    Returns whether or not this ExtensionVersion is named ‘other’.

    Parameters:

    • other (String)

      An extension name

    Returns:

    • (Boolean)

      whether or not this ExtensionVersion is named ‘other’

  • #==(other) ⇒ Boolean

    Returns whether or not this ExtensionVersion has the exact same name and version as other.

    Parameters:

    Returns:

    • (Boolean)

      whether or not this ExtensionVersion has the exact same name and version as other



344
345
346
347
348
349
350
351
352
353
# File 'lib/arch_obj_models/extension.rb', line 344

def ==(other)
  case other
  when String
    @name == other
  when ExtensionVersion
    @name == other.name && @version == other.version
  else
    raise "Unexpected comparison"
  end
end

#changesObject



315
# File 'lib/arch_obj_models/extension.rb', line 315

def changes = @data["changes"].nil? ? [] : @data["changes"]

#contributorsObject



319
320
321
322
323
324
325
326
327
# File 'lib/arch_obj_models/extension.rb', line 319

def contributors
  return @contributors unless @contributors.nil?

  @contributors = []
  @data["contributors"]&.each do |c|
    @contributors << Person.new(c)
  end
  @contributors
end

#eql?(other) ⇒ Boolean

Returns Whether or not other is an ExtensionVersion with the same name and version.

Parameters:

Returns:

  • (Boolean)

    Whether or not other is an ExtensionVersion with the same name and version



357
358
359
360
361
# File 'lib/arch_obj_models/extension.rb', line 357

def eql?(other)
  return false unless other.is_a?(ExtensionVersion)

  @name == other.name && @version == other.version
end

#implemented_csrs(archdef) ⇒ Array<Csr>

Returns the list of CSRs implemented by this extension version (may be empty).

Returns:

  • (Array<Csr>)

    the list of CSRs implemented by this extension version (may be empty)



420
421
422
423
424
425
426
427
428
# File 'lib/arch_obj_models/extension.rb', line 420

def implemented_csrs(archdef)
  raise "should only be called with a fully configured arch def" unless archdef.fully_configured?

  return @implemented_csrs unless @implemented_csrs.nil?

  @implemented_csrs = archdef.implemented_csrs.select do |csr|
    csr.defined_by?(self)
  end
end

#implemented_instructions(archdef) ⇒ Array<Csr>

Returns the list of CSRs implemented by this extension version (may be empty).

Returns:

  • (Array<Csr>)

    the list of CSRs implemented by this extension version (may be empty)



431
432
433
434
435
436
437
438
439
# File 'lib/arch_obj_models/extension.rb', line 431

def implemented_instructions(archdef)
  raise "should only be called with a fully configured arch def" unless archdef.fully_configured?

  return @implemented_instructions unless @implemented_instructions.nil?

  @implemented_instructions = archdef.implemented_instructions.select do |inst|
    inst.defined_by?(self)
  end
end

#implicationsObject



382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
# File 'lib/arch_obj_models/extension.rb', line 382

def implications
  return @implications unless @implications.nil?

  @implications = []
  case @data["implies"]
  when nil
    return @implications
  when Array
    if @data["implies"][0].is_a?(Array)
      @implications += @data["implies"].map { |e| ExtensionVersion.new(e[0], e[1], @arch_def) }
    else
      @implications << ExtensionVersion.new(@data["implies"][0], @data["implies"][1], @arch_def)
    end
  end
  @implications.uniq!
  @implications
end

#paramsArray<ExtensionParameter>

Returns The list of parameters for this extension version.

Returns:



330
331
332
# File 'lib/arch_obj_models/extension.rb', line 330

def params
  @ext.params.select { |p| p.defined_in_extension_version?(@version) }
end

#ratification_dateObject



313
# File 'lib/arch_obj_models/extension.rb', line 313

def ratification_date = @data["ratification_date"]

#requirementsObject



363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
# File 'lib/arch_obj_models/extension.rb', line 363

def requirements
  r = case @data["requires"]
      when nil
        AlwaysTrueSchemaCondition.new
      when Hash
        SchemaCondition.new(@data["requires"])
      else
        SchemaCondition.new({"oneOf" => [@data["requires"]]})
      end
  if @data.key?("implies")
    rs = [r] + implications.map { |e| e.requirements }
    rs = rs.reject { |r| r.empty? }
    unless rs.empty?
      r = SchemaCondition.all_of(*rs.map { |r| r.to_h })
    end
  end
  r
end

#satisfies?(ext_name, *ext_version_requirements) ⇒ Boolean

Returns whether or not this ExtensionVersion is named ‘ext_name` and satifies the version requirements.

Parameters:

  • ext_name (String)

    Extension name

  • ext_version_requirements (Number, String, Array)

    Extension version requirements, taking the same inputs as Gem::Requirement

Returns:

  • (Boolean)

    whether or not this ExtensionVersion is named ‘ext_name` and satifies the version requirements

See Also:



404
405
406
# File 'lib/arch_obj_models/extension.rb', line 404

def satisfies?(ext_name, *ext_version_requirements)
  @name == ext_name && Gem::Requirement.new(ext_version_requirements).satisfied_by?(@version)
end

#stateString

Returns The state of the extension version (‘ratified’, ‘developemnt’, etc).

Returns:

  • (String)

    The state of the extension version (‘ratified’, ‘developemnt’, etc)



311
# File 'lib/arch_obj_models/extension.rb', line 311

def state = @data["state"]

#to_sObject



334
335
336
# File 'lib/arch_obj_models/extension.rb', line 334

def to_s
  "#{name}@#{version}"
end

#urlObject



317
# File 'lib/arch_obj_models/extension.rb', line 317

def url = @data["url"]