Class: ExtensionVersion
- Inherits:
-
Object
- Object
- ExtensionVersion
- Defined in:
- lib/arch_obj_models/extension.rb
Overview
A specific version of an extension
Instance Attribute Summary collapse
-
#ext ⇒ Extension
readonly
Extension.
-
#name ⇒ String
readonly
Name of the extension.
-
#version ⇒ Gem::Version
readonly
Version of the extension.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
sorts extension by name, then by version.
- #==(other) ⇒ Object
- #changes ⇒ Object
- #contributors ⇒ Object
-
#eql?(other) ⇒ Boolean
Whether or not
other
is an ExtensionVersion with the same name and version. -
#implemented_csrs(archdef) ⇒ Array<Csr>
The list of CSRs implemented by this extension version (may be empty).
-
#implemented_instructions(archdef) ⇒ Array<Csr>
The list of CSRs implemented by this extension version (may be empty).
- #implications ⇒ Object
-
#initialize(name, version, arch_def) ⇒ ExtensionVersion
constructor
A new instance of ExtensionVersion.
-
#params ⇒ Array<ExtensionParameter>
The list of parameters for this extension version.
- #ratification_date ⇒ Object
- #requirements ⇒ Object
-
#satisfies?(ext_name, *ext_version_requirements) ⇒ Boolean
Whether or not this ExtensionVersion is named ‘ext_name` and satifies the version requirements.
-
#state ⇒ String
The state of the extension version (‘ratified’, ‘developemnt’, etc).
- #to_s ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(name, version, arch_def) ⇒ ExtensionVersion
Returns a new instance of ExtensionVersion.
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
#ext ⇒ Extension (readonly)
Returns Extension.
292 293 294 |
# File 'lib/arch_obj_models/extension.rb', line 292 def ext @ext end |
#name ⇒ String (readonly)
Returns Name of the extension.
286 287 288 |
# File 'lib/arch_obj_models/extension.rb', line 286 def name @name end |
#version ⇒ Gem::Version (readonly)
Returns 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
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
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 |
#changes ⇒ Object
315 |
# File 'lib/arch_obj_models/extension.rb', line 315 def changes = @data["changes"].nil? ? [] : @data["changes"] |
#contributors ⇒ Object
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.
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).
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).
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 |
#implications ⇒ Object
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 |
#params ⇒ Array<ExtensionParameter>
Returns The list of parameters for this extension version.
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_date ⇒ Object
313 |
# File 'lib/arch_obj_models/extension.rb', line 313 def ratification_date = @data["ratification_date"] |
#requirements ⇒ Object
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.
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 |
#state ⇒ String
Returns The state of the extension version (‘ratified’, ‘developemnt’, etc).
311 |
# File 'lib/arch_obj_models/extension.rb', line 311 def state = @data["state"] |
#to_s ⇒ Object
334 335 336 |
# File 'lib/arch_obj_models/extension.rb', line 334 def to_s "#{name}@#{version}" end |
#url ⇒ Object
317 |
# File 'lib/arch_obj_models/extension.rb', line 317 def url = @data["url"] |