Class: Verquest::Properties::Base Abstract
- Inherits:
-
Object
- Object
- Verquest::Properties::Base
- 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.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#map ⇒ String?
The mapping path for this property.
-
#name ⇒ String
The name of the property.
-
#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`.
Instance Attribute Details
#map ⇒ String?
Returns The mapping path for this property.
19 |
# File 'lib/verquest/properties/base.rb', line 19 attr_accessor :name, :required, :map |
#name ⇒ String
Returns The name of the property.
19 20 21 |
# File 'lib/verquest/properties/base.rb', line 19 def name @name end |
#required ⇒ Boolean
Returns Whether this property is required.
19 |
# File 'lib/verquest/properties/base.rb', line 19 attr_accessor :name, :required, :map |
Instance Method Details
#add(property) ⇒ Object
Adds a child property to this property
25 26 27 |
# File 'lib/verquest/properties/base.rb', line 25 def add(property) raise NoMethodError end |
#mapping(key_prefix:, value_prefix:, mapping:, version:) ⇒ Hash
Creates mapping for this property
52 53 54 |
# File 'lib/verquest/properties/base.rb', line 52 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
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/verquest/properties/base.rb', line 62 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
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/verquest/properties/base.rb', line 84 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
33 34 35 |
# File 'lib/verquest/properties/base.rb', line 33 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`
40 41 42 |
# File 'lib/verquest/properties/base.rb', line 40 def to_validation_schema(version: nil) to_schema end |