Class: Verquest::Properties::Base Abstract
- Inherits:
-
Object
- Object
- Verquest::Properties::Base
- Includes:
- HelperMethods::RequiredProperties
- Defined in:
- lib/verquest/properties/base.rb
Overview
Subclass and override #to_schema, #mapping to implement
Base class for all property types
This abstract class defines the interface for all property types in the Verquest schema system. All property classes should inherit from this base class and implement its required methods.
Instance Attribute Summary collapse
-
#map ⇒ String?
The mapping path for this property.
-
#name ⇒ String
The name of the property.
-
#nullable ⇒ Object
readonly
private
Returns the value of attribute nullable.
-
#required ⇒ Boolean
Whether this property is required.
Instance Method Summary collapse
-
#add(property) ⇒ Object
abstract
Adds a child property to this property.
-
#mapping(key_prefix:, value_prefix:, mapping:, version:) ⇒ Hash
abstract
Creates mapping for this property.
-
#mapping_value_key(value_prefix:, collection: false) ⇒ String
private
Determines the mapping target key based on mapping configuration.
-
#mapping_value_prefix(value_prefix:, collection: false) ⇒ Array<String>
private
Determines the mapping target value prefix based on mapping configuration.
-
#to_schema ⇒ Hash
abstract
Generates JSON schema for this property.
-
#to_validation_schema(version: nil) ⇒ Hash
Generates validation schema for this property, defaults to the same as
to_schema.
Methods included from HelperMethods::RequiredProperties
#dependent_required_properties, #required_properties
Instance Attribute Details
#map ⇒ String?
Returns The mapping path for this property.
21 |
# File 'lib/verquest/properties/base.rb', line 21 attr_accessor :name, :required, :map |
#name ⇒ String
Returns The name of the property.
21 22 23 |
# File 'lib/verquest/properties/base.rb', line 21 def name @name end |
#nullable ⇒ Object (readonly, private)
Returns the value of attribute nullable.
62 63 64 |
# File 'lib/verquest/properties/base.rb', line 62 def nullable @nullable end |
#required ⇒ Boolean
Returns Whether this property is required.
21 |
# File 'lib/verquest/properties/base.rb', line 21 attr_accessor :name, :required, :map |
Instance Method Details
#add(property) ⇒ Object
Adds a child property to this property
27 28 29 |
# File 'lib/verquest/properties/base.rb', line 27 def add(property) raise NoMethodError end |
#mapping(key_prefix:, value_prefix:, mapping:, version:) ⇒ Hash
Creates mapping for this property
54 55 56 |
# File 'lib/verquest/properties/base.rb', line 54 def mapping(key_prefix:, value_prefix:, mapping:, version:) raise NoMethodError end |
#mapping_value_key(value_prefix:, collection: false) ⇒ String (private)
Determines the mapping target key based on mapping configuration
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/verquest/properties/base.rb', line 68 def mapping_value_key(value_prefix:, collection: false) value_key = if map.nil? (value_prefix + [name]).join("/") elsif map == "/" "" elsif map.start_with?("/") map.gsub(%r{^/}, "") else (value_prefix + map.split("/")).join("/") end if collection value_key + "[]" else value_key end end |
#mapping_value_prefix(value_prefix:, collection: false) ⇒ Array<String> (private)
Determines the mapping target value prefix based on mapping configuration
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/verquest/properties/base.rb', line 90 def mapping_value_prefix(value_prefix:, collection: false) value_prefix = if map.nil? value_prefix + [name] elsif map == "/" [] elsif map.start_with?("/") map.gsub(%r{^/}, "").split("/") else value_prefix + map.split("/") end if collection && value_prefix.any? last = value_prefix.pop value_prefix.push((last.to_s + "[]").to_sym) end value_prefix end |
#to_schema ⇒ Hash
Generates JSON schema for this property
35 36 37 |
# File 'lib/verquest/properties/base.rb', line 35 def to_schema raise NoMethodError end |
#to_validation_schema(version: nil) ⇒ Hash
Generates validation schema for this property, defaults to the same as to_schema
42 43 44 |
# File 'lib/verquest/properties/base.rb', line 42 def to_validation_schema(version: nil) to_schema end |