Class: Udb::Parameter

Inherits:
TopLevelDatabaseObject show all
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

Defined Under Namespace

Classes: NoMatchingSchemaError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(yaml, data_path, cfg_arch)

Parameters:



69
70
71
72
73
# File 'lib/udb/obj/parameter.rb', line 69

def initialize(yaml, data_path, cfg_arch)
  super(yaml, data_path, cfg_arch)

  @schema = Schema.new(data["schema"])
end

Instance Attribute Details

#cfg_archConfiguredArchitecture (readonly)

Returns The defining architecture.

Returns:



25
26
27
# File 'lib/udb/obj/parameter.rb', line 25

def cfg_arch
  @cfg_arch
end

#schemaSchema (readonly)

Returns JSON Schema for this param.

Returns:

  • (Schema)

    JSON Schema for this param



77
78
79
# File 'lib/udb/obj/parameter.rb', line 77

def schema
  @schema
end

Instance Method Details

#<=>(other) ⇒ Integer?

sorts by name

Parameters:

  • other (T.untyped)

Returns:

  • (Integer, nil)


109
110
111
112
113
# File 'lib/udb/obj/parameter.rb', line 109

def <=>(other)
  return nil unless other.is_a?(Idl::RuntimeParam)

  @name <=> other.name
end

#defaultObject?

Returns:

  • (Object, nil)


56
57
58
59
60
# File 'lib/udb/obj/parameter.rb', line 56

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.

Parameters:

Returns:

  • (SatisfiedResult)

    if this parameter is defined in cfg_arch



89
90
91
# File 'lib/udb/obj/parameter.rb', line 89

def defined_in_cfg?(cfg_arch)
  defined_by_condition.satisfied_by_cfg_arch?(cfg_arch)
end

#idl_typeIdl::Type

Returns:

  • (Idl::Type)


83
84
85
# File 'lib/udb/obj/parameter.rb', line 83

def idl_type
  @idl_type ||= schema.to_idl_type.make_const.freeze
end

#nameString

Returns Parameter name.

Returns:

  • (String)

    Parameter name



29
# File 'lib/udb/obj/parameter.rb', line 29

def name = @name

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.

Parameters:

  • exts

    List of all in-scope extensions that define this parameter.

  • in_scope_exts (Array<Extension>)

Returns:

  • (String)

    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.



97
98
99
100
101
102
103
104
105
# File 'lib/udb/obj/parameter.rb', line 97

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

#requirements_conditionAbstractCondition

Returns:



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/udb/obj/parameter.rb', line 38

def requirements_condition
  @requirements_condition ||=
    begin
      if @data["requirements"].nil?
        AlwaysTrueCondition.new(@cfg_arch)
      else
        Condition.new(
          @data.fetch("requirements"),
          @cfg_arch,
          input_file: Pathname.new(__source),
          input_line: source_line(["requirements"])
        )
      end
    end
end

#schema_typeString

Pretty convert extension schema to a string.

Returns:

  • (String)


33
34
35
# File 'lib/udb/obj/parameter.rb', line 33

def schema_type
  schema.to_pretty_s
end

#to_idlString

Returns:

  • (String)


116
# File 'lib/udb/obj/parameter.rb', line 116

def to_idl = "#{idl_type.to_idl} #{name}"

#valueIdl::RuntimeParam::ValueType

Returns:

  • (Idl::RuntimeParam::ValueType)


122
# File 'lib/udb/obj/parameter.rb', line 122

def value = raise "Parameter value not known for #{name}"

#value_known?Boolean

Returns:

  • (Boolean)


119
# File 'lib/udb/obj/parameter.rb', line 119

def value_known? = false