Class: Udb::Parameter
- Inherits:
-
Object
- Object
- Udb::Parameter
- Extended by:
- T::Sig
- Includes:
- Idl::RuntimeParam
- Defined in:
- lib/udb/obj/parameter.rb
Overview
A parameter (AKA option, AKA implementation-defined value) supported by an extension
Instance Attribute Summary collapse
-
#cfg_arch ⇒ ConfiguredArchitecture
readonly
The defining architecture.
-
#desc ⇒ String
readonly
Asciidoc description.
- #extra_validation ⇒ nil, String readonly
-
#exts ⇒ Array<Extension>
readonly
Some parameters are defined by multiple extensions (e.g., CACHE_BLOCK_SIZE by Zicbom and Zicboz).
- #idl_type ⇒ Idl::Type readonly
-
#schema ⇒ Schema
readonly
JSON Schema for this param.
Instance Method Summary collapse
-
#<=>(other) ⇒ Integer?
sorts by name.
- #default ⇒ Object?
-
#defined_in_cfg?(cfg_arch) ⇒ SatisfiedResult
If this parameter is defined in
cfg_arch
. - #initialize(ext, name, data) constructor
-
#name ⇒ String
Parameter name.
-
#name_potentially_with_link(in_scope_exts) ⇒ String
Text to create a link to the parameter definition with the link text the parameter name.
-
#schema_type ⇒ String
Pretty convert extension schema to a string.
- #to_idl ⇒ String
- #value ⇒ Idl::RuntimeParam::ValueType
- #value_known? ⇒ Boolean
-
#when ⇒ ExtensionRequirementExpression
Condition when the parameter exists.
Constructor Details
#initialize(ext, name, data)
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/udb/obj/parameter.rb', line 69 def initialize(ext, name, data) @cfg_arch = T.let(ext.cfg_arch, ConfiguredArchitecture) @data = T.let(data, T::Hash[String, T.untyped]) @name = T.let(name, String) @desc = T.let(T.cast(data["description"], String), String) @schema = T.let(Schema.new(data["schema"]), Schema) @extra_validation = T.let(data.key?("extra_validation") ? T.let(T.cast(data["extra_validation"], String), String) : nil, T.nilable(String)) also_defined_in_array = [] also_defined_in_data = data["also_defined_in"] unless also_defined_in_data.nil? other_ext = T.let(nil, T.nilable(Extension)) if also_defined_in_data.is_a?(String) other_ext_name = also_defined_in_data other_ext = @cfg_arch.extension(other_ext_name) raise "Definition error in #{ext.name}.#{name}: #{other_ext_name} is not a known extension" if other_ext.nil? also_defined_in_array << other_ext else unless also_defined_in_data.is_a?(Array) && also_defined_in_data.all? { |e| e.is_a?(String) } raise "schema error: also_defined_in should be a string or array of strings" end also_defined_in_data.each do |other_ext_name| other_ext = @cfg_arch.extension(other_ext_name) raise "Definition error in #{ext.name}.#{name}: #{also_defined_in_data} is not a known extension" if other_ext.nil? also_defined_in_array << other_ext end end end @exts = T.let([ext] + also_defined_in_array, T::Array[Extension]) @idl_type = T.let(@schema.to_idl_type.make_const.freeze, ::Idl::Type) @when = T.let(nil, T.nilable(ExtensionRequirementExpression)) end |
Instance Attribute Details
#cfg_arch ⇒ ConfiguredArchitecture (readonly)
Returns The defining architecture.
24 25 26 |
# File 'lib/udb/obj/parameter.rb', line 24 def cfg_arch @cfg_arch end |
#desc ⇒ String (readonly)
Returns Asciidoc description.
32 33 34 |
# File 'lib/udb/obj/parameter.rb', line 32 def desc @desc end |
#extra_validation ⇒ nil, String (readonly)
41 42 43 |
# File 'lib/udb/obj/parameter.rb', line 41 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 exact same thing.
48 49 50 |
# File 'lib/udb/obj/parameter.rb', line 48 def exts @exts end |
#idl_type ⇒ Idl::Type (readonly)
52 53 54 |
# File 'lib/udb/obj/parameter.rb', line 52 def idl_type @idl_type end |
#schema ⇒ Schema (readonly)
Returns JSON Schema for this param.
36 37 38 |
# File 'lib/udb/obj/parameter.rb', line 36 def schema @schema end |
Instance Method Details
#<=>(other) ⇒ Integer?
sorts by name
161 |
# File 'lib/udb/obj/parameter.rb', line 161 def <=>(other) = @name <=> other.name |
#default ⇒ Object?
62 63 64 65 66 |
# File 'lib/udb/obj/parameter.rb', line 62 def default if T.cast(@data["schema"], T::Hash[String, Object]).key?("default") T.cast(@data["schema"], T::Hash[String, Object])["default"] end end |
#defined_in_cfg?(cfg_arch) ⇒ SatisfiedResult
Returns if this parameter is defined in cfg_arch
.
133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/udb/obj/parameter.rb', line 133 def defined_in_cfg?(cfg_arch) if @exts.none? { |ext| cfg_arch.possible_extensions.any? { |e| e.name == ext.name } } return SatisfiedResult::No end if @when.nil? return SatisfiedResult::Yes end @when.satisfied_by_cfg_arch?(cfg_arch) end |
#name ⇒ String
Returns Parameter name.
28 |
# File 'lib/udb/obj/parameter.rb', line 28 def name = @name |
#name_potentially_with_link(in_scope_exts) ⇒ String
Returns Text to create a link to the parameter definition with the link text the parameter name. if only one extension defines the parameter, otherwise just the parameter name.
149 150 151 152 153 154 155 156 157 |
# File 'lib/udb/obj/parameter.rb', line 149 def name_potentially_with_link(in_scope_exts) helper = Class.new do include Udb::Helpers::TemplateHelpers end if in_scope_exts.size == 1 helper.new.link_to_udb_doc_ext_param(in_scope_exts.fetch(0).name, name, name) else name end end |
#schema_type ⇒ String
Pretty convert extension schema to a string.
56 57 58 |
# File 'lib/udb/obj/parameter.rb', line 56 def schema_type @schema.to_pretty_s end |
#to_idl ⇒ String
164 |
# File 'lib/udb/obj/parameter.rb', line 164 def to_idl = "#{idl_type.to_idl} #{name}" |
#value ⇒ Idl::RuntimeParam::ValueType
170 |
# File 'lib/udb/obj/parameter.rb', line 170 def value = raise "Parameter value not known for #{name}" |
#value_known? ⇒ Boolean
167 |
# File 'lib/udb/obj/parameter.rb', line 167 def value_known? = false |
#when ⇒ ExtensionRequirementExpression
Returns Condition when the parameter exists.
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/udb/obj/parameter.rb', line 107 def when @when ||= if @data["when"].nil? # the parent extension is implictly required cond = if @exts.size > 1 { "anyOf" => @exts.map { |ext| { "name" => ext.name, "version" => ">= #{ext.min_version.version_str}" } }} else { "name" => @exts.fetch(0).name, "version" => ">= #{@exts.fetch(0).min_version.version_str}"} end ExtensionRequirementExpression.new(cond, @cfg_arch) else # the parent extension is implictly required cond = if @exts.size > 1 { "allOf" => [{"anyOf" => @exts.map { |ext| { "name" => ext.name, "version" => ">= #{ext.min_version.version_str}" } } }, @data["when"]] } else { "allOf" => [ { "name" => @exts.fetch(0).name, "version" => ">= #{@exts.fetch(0).min_version.version_str}"}, @data["when"]] } end ExtensionRequirementExpression.new(cond, @cfg_arch) end end |