Class: Lutaml::Hal::EndpointParameter::Schema
- Inherits:
-
Object
- Object
- Lutaml::Hal::EndpointParameter::Schema
- Defined in:
- lib/lutaml/hal/endpoint_parameter.rb
Overview
Schema validation and type checking
Instance Attribute Summary collapse
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#enum ⇒ Object
readonly
Returns the value of attribute enum.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#items ⇒ Object
readonly
Returns the value of attribute items.
-
#max_length ⇒ Object
readonly
Returns the value of attribute max_length.
-
#maximum ⇒ Object
readonly
Returns the value of attribute maximum.
-
#min_length ⇒ Object
readonly
Returns the value of attribute min_length.
-
#minimum ⇒ Object
readonly
Returns the value of attribute minimum.
-
#nullable ⇒ Object
readonly
Returns the value of attribute nullable.
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(definition = {}) ⇒ Schema
constructor
A new instance of Schema.
- #validate(value) ⇒ Object
- #validate_definition! ⇒ Object
Constructor Details
#initialize(definition = {}) ⇒ Schema
Returns a new instance of Schema.
93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/lutaml/hal/endpoint_parameter.rb', line 93 def initialize(definition = {}) @type = definition[:type] || :string @format = definition[:format] @enum = definition[:enum] @minimum = definition[:minimum] @maximum = definition[:maximum] @min_length = definition[:min_length] @max_length = definition[:max_length] @pattern = definition[:pattern] @items = definition[:items] @default = definition[:default] @nullable = definition[:nullable] || false end |
Instance Attribute Details
#default ⇒ Object (readonly)
Returns the value of attribute default.
90 91 92 |
# File 'lib/lutaml/hal/endpoint_parameter.rb', line 90 def default @default end |
#enum ⇒ Object (readonly)
Returns the value of attribute enum.
90 91 92 |
# File 'lib/lutaml/hal/endpoint_parameter.rb', line 90 def enum @enum end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
90 91 92 |
# File 'lib/lutaml/hal/endpoint_parameter.rb', line 90 def format @format end |
#items ⇒ Object (readonly)
Returns the value of attribute items.
90 91 92 |
# File 'lib/lutaml/hal/endpoint_parameter.rb', line 90 def items @items end |
#max_length ⇒ Object (readonly)
Returns the value of attribute max_length.
90 91 92 |
# File 'lib/lutaml/hal/endpoint_parameter.rb', line 90 def max_length @max_length end |
#maximum ⇒ Object (readonly)
Returns the value of attribute maximum.
90 91 92 |
# File 'lib/lutaml/hal/endpoint_parameter.rb', line 90 def maximum @maximum end |
#min_length ⇒ Object (readonly)
Returns the value of attribute min_length.
90 91 92 |
# File 'lib/lutaml/hal/endpoint_parameter.rb', line 90 def min_length @min_length end |
#minimum ⇒ Object (readonly)
Returns the value of attribute minimum.
90 91 92 |
# File 'lib/lutaml/hal/endpoint_parameter.rb', line 90 def minimum @minimum end |
#nullable ⇒ Object (readonly)
Returns the value of attribute nullable.
90 91 92 |
# File 'lib/lutaml/hal/endpoint_parameter.rb', line 90 def nullable @nullable end |
#pattern ⇒ Object (readonly)
Returns the value of attribute pattern.
90 91 92 |
# File 'lib/lutaml/hal/endpoint_parameter.rb', line 90 def pattern @pattern end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
90 91 92 |
# File 'lib/lutaml/hal/endpoint_parameter.rb', line 90 def type @type end |
Instance Method Details
#validate(value) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/lutaml/hal/endpoint_parameter.rb', line 107 def validate(value) return true if value.nil? && @nullable return false if value.nil? && !@nullable case @type when :string validate_string(value) when :integer validate_integer(value) when :number validate_number(value) when :boolean validate_boolean(value) when :array validate_array(value) else true end end |
#validate_definition! ⇒ Object
127 128 129 130 131 132 133 134 |
# File 'lib/lutaml/hal/endpoint_parameter.rb', line 127 def validate_definition! valid_types = %i[string integer number boolean array object] raise ArgumentError, "Invalid schema type: #{@type}" unless valid_types.include?(@type) return unless @type == :array && @items.nil? raise ArgumentError, "Array type requires 'items' definition" end |