Class: ExtensionParameter
- Inherits:
-
Object
- Object
- ExtensionParameter
- Defined in:
- lib/arch_obj_models/extension.rb
Overview
A parameter (AKA option, AKA implementation-defined value) supported by an extension
Instance Attribute Summary collapse
-
#archdef ⇒ ArchDef
readonly
The defining Arch def.
-
#desc ⇒ String
readonly
Asciidoc description.
- #extra_validation ⇒ String? readonly
-
#exts ⇒ Array<Extension>
readonly
Some parameters are defined by multiple extensions (e.g., CACHE_BLOCK_SIZE by Zicbom and Zicboz).
-
#idl_type ⇒ Object
readonly
Returns the value of attribute idl_type.
-
#name ⇒ String
readonly
Parameter name.
-
#schema ⇒ Schema
readonly
JSON Schema for this param.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
sorts by name.
- #defined_in_extension_version?(version) ⇒ Boolean
-
#initialize(ext, name, data) ⇒ ExtensionParameter
constructor
A new instance of ExtensionParameter.
- #name_potentially_with_link(exts) ⇒ String
-
#schema_type ⇒ Object
Pretty convert extension schema to a string.
Constructor Details
#initialize(ext, name, data) ⇒ ExtensionParameter
Returns a new instance of ExtensionParameter.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/arch_obj_models/extension.rb', line 38 def initialize(ext, name, data) @archdef = ext.arch_def @data = data @name = name @desc = data["description"] @schema = Schema.new(data["schema"]) @extra_validation = data["extra_validation"] also_defined_in = [] unless data["also_defined_in"].nil? if data["also_defined_in"].is_a?(String) other_ext = @archdef.extension(data["also_defined_in"]) raise "Definition error in #{ext.name}.#{name}: #{data['also_defined_in']} is not a known extension" if other_ext.nil? also_defined_in << other_ext else unless data["also_defined_in"].is_a?(Array) && data["also_defined_in"].all? { |e| e.is_a?(String) } raise "schema error: also_defined_in should be a string or array of strings" end data["also_defined_in"].each do |other_ext_name| other_ext = @archdef.extension(other_ext_name) raise "Definition error in #{ext.name}.#{name}: #{data['also_defined_in']} is not a known extension" if other_ext.nil? also_defined_in << other_ext end end end @exts = [ext] + also_defined_in @idl_type = @schema.to_idl_type.make_const.freeze end |
Instance Attribute Details
#archdef ⇒ ArchDef (readonly)
Returns The defining Arch def.
9 10 11 |
# File 'lib/arch_obj_models/extension.rb', line 9 def archdef @archdef end |
#desc ⇒ String (readonly)
Returns Asciidoc description.
15 16 17 |
# File 'lib/arch_obj_models/extension.rb', line 15 def desc @desc end |
#extra_validation ⇒ String? (readonly)
22 23 24 |
# File 'lib/arch_obj_models/extension.rb', line 22 def extra_validation @extra_validation end |
#exts ⇒ Array<Extension> (readonly)
Some parameters are defined by multiple extensions (e.g., CACHE_BLOCK_SIZE by Zicbom and Zicboz). When defined in multiple places, the parameter must mean the extact same thing.
28 29 30 |
# File 'lib/arch_obj_models/extension.rb', line 28 def exts @exts end |
#idl_type ⇒ Object (readonly)
Returns the value of attribute idl_type.
31 32 33 |
# File 'lib/arch_obj_models/extension.rb', line 31 def idl_type @idl_type end |
#name ⇒ String (readonly)
Returns Parameter name.
12 13 14 |
# File 'lib/arch_obj_models/extension.rb', line 12 def name @name end |
#schema ⇒ Schema (readonly)
Returns JSON Schema for this param.
18 19 20 |
# File 'lib/arch_obj_models/extension.rb', line 18 def schema @schema end |
Instance Method Details
#<=>(other) ⇒ Object
sorts by name
86 87 88 89 90 |
# File 'lib/arch_obj_models/extension.rb', line 86 def <=>(other) raise ArgumentError, "ExtensionParameters are only comparable to other extension parameters" unless other.is_a?(ExtensionParameter) @name <=> other.name end |
#defined_in_extension_version?(version) ⇒ Boolean
67 68 69 70 71 |
# File 'lib/arch_obj_models/extension.rb', line 67 def defined_in_extension_version?(version) return true if @data.dig("when", "version").nil? Gem::Requirement.new(@data["when"]["version"]).satisfied_by?(Gem::Version.new(version)) end |
#name_potentially_with_link(exts) ⇒ String
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/arch_obj_models/extension.rb', line 74 def name_potentially_with_link(exts) raise ArgumentError, "Expecting Array" unless exts.is_a?(Array) raise ArgumentError, "Expecting Array[Extension]" unless exts[0].is_a?(Extension) if exts.size == 1 "<<ext-#{exts[0].name}-param-#{name}-def,#{name}>>" else "#{name}" end end |
#schema_type ⇒ Object
Pretty convert extension schema to a string.
34 35 36 |
# File 'lib/arch_obj_models/extension.rb', line 34 def schema_type @schema.to_pretty_s end |