Class: Verquest::Properties::Const
- Defined in:
- lib/verquest/properties/const.rb
Overview
The Const class represents a constant property with a fixed value in a JSON schema. It’s used for properties that must have a specific, immutable value.
Instance Attribute Summary collapse
-
#schema_options ⇒ Object
readonly
private
Returns the value of attribute schema_options.
-
#value ⇒ Object
readonly
private
Returns the value of attribute value.
Attributes inherited from Base
#map, #name, #nullable, #required
Instance Method Summary collapse
-
#initialize(name:, value:, map: nil, required: false, **schema_options) ⇒ Const
constructor
Initialize a new constant property.
-
#mapping(key_prefix:, value_prefix:, mapping:, version: nil) ⇒ Hash
Create mapping for this const property.
-
#to_schema ⇒ Hash
Generate JSON schema definition for this constant.
Methods inherited from Base
#add, #mapping_value_key, #mapping_value_prefix, #to_validation_schema
Methods included from HelperMethods::RequiredProperties
#dependent_required_properties, #required_properties
Constructor Details
#initialize(name:, value:, map: nil, required: false, **schema_options) ⇒ Const
Initialize a new constant property
18 19 20 21 22 23 24 |
# File 'lib/verquest/properties/const.rb', line 18 def initialize(name:, value:, map: nil, required: false, **) @name = name.to_s @value = value @map = map @required = required @schema_options = &.transform_keys(&:to_s) end |
Instance Attribute Details
#schema_options ⇒ Object (readonly, private)
Returns the value of attribute schema_options.
50 51 52 |
# File 'lib/verquest/properties/const.rb', line 50 def @schema_options end |
#value ⇒ Object (readonly, private)
Returns the value of attribute value.
50 51 52 |
# File 'lib/verquest/properties/const.rb', line 50 def value @value end |
Instance Method Details
#mapping(key_prefix:, value_prefix:, mapping:, version: nil) ⇒ Hash
Create mapping for this const property
44 45 46 |
# File 'lib/verquest/properties/const.rb', line 44 def mapping(key_prefix:, value_prefix:, mapping:, version: nil) mapping[(key_prefix + [name]).join("/")] = mapping_value_key(value_prefix:) end |
#to_schema ⇒ Hash
Generate JSON schema definition for this constant
29 30 31 32 33 34 35 |
# File 'lib/verquest/properties/const.rb', line 29 def to_schema { name => { "const" => value }.merge() } end |