Class: ActionSpec::Schema::Base
- Inherits:
-
Object
- Object
- ActionSpec::Schema::Base
- Defined in:
- lib/action_spec/schema/base.rb
Instance Attribute Summary collapse
-
#blank ⇒ Object
(also: #allow_blank)
readonly
Returns the value of attribute blank.
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#enum ⇒ Object
readonly
Returns the value of attribute enum.
-
#example ⇒ Object
readonly
Returns the value of attribute example.
-
#examples ⇒ Object
readonly
Returns the value of attribute examples.
-
#length ⇒ Object
readonly
Returns the value of attribute length.
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
-
#range ⇒ Object
readonly
Returns the value of attribute range.
Instance Method Summary collapse
- #blank_allowed? ⇒ Boolean
- #blank_value(_value) ⇒ Object
- #copy ⇒ Object
- #custom_validation? ⇒ Boolean
-
#initialize(options = {}) ⇒ Base
constructor
A new instance of Base.
- #materialize_missing(context:, coerce:, result:, path:) ⇒ Object
- #validate_constraints(value, result:, path:, field: nil, context: nil) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Base
Returns a new instance of Base.
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/action_spec/schema/base.rb', line 8 def initialize( = {}) = .symbolize_keys @default = [:default] @enum = [:enum] @range = [:range] @pattern = [:pattern] @length = [:length] @blank = .key?(:blank) ? [:blank] : .fetch(:allow_blank, true) @description = [:desc] || [:description] @example = [:example] @examples = [:examples] end |
Instance Attribute Details
#blank ⇒ Object (readonly) Also known as: allow_blank
Returns the value of attribute blank.
6 7 8 |
# File 'lib/action_spec/schema/base.rb', line 6 def blank @blank end |
#default ⇒ Object (readonly)
Returns the value of attribute default.
6 7 8 |
# File 'lib/action_spec/schema/base.rb', line 6 def default @default end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
6 7 8 |
# File 'lib/action_spec/schema/base.rb', line 6 def description @description end |
#enum ⇒ Object (readonly)
Returns the value of attribute enum.
6 7 8 |
# File 'lib/action_spec/schema/base.rb', line 6 def enum @enum end |
#example ⇒ Object (readonly)
Returns the value of attribute example.
6 7 8 |
# File 'lib/action_spec/schema/base.rb', line 6 def example @example end |
#examples ⇒ Object (readonly)
Returns the value of attribute examples.
6 7 8 |
# File 'lib/action_spec/schema/base.rb', line 6 def examples @examples end |
#length ⇒ Object (readonly)
Returns the value of attribute length.
6 7 8 |
# File 'lib/action_spec/schema/base.rb', line 6 def length @length end |
#pattern ⇒ Object (readonly)
Returns the value of attribute pattern.
6 7 8 |
# File 'lib/action_spec/schema/base.rb', line 6 def pattern @pattern end |
#range ⇒ Object (readonly)
Returns the value of attribute range.
6 7 8 |
# File 'lib/action_spec/schema/base.rb', line 6 def range @range end |
Instance Method Details
#blank_allowed? ⇒ Boolean
31 32 33 |
# File 'lib/action_spec/schema/base.rb', line 31 def blank_allowed? blank != false end |
#blank_value(_value) ⇒ Object
27 28 29 |
# File 'lib/action_spec/schema/base.rb', line 27 def blank_value(_value) nil end |
#copy ⇒ Object
43 44 45 |
# File 'lib/action_spec/schema/base.rb', line 43 def copy raise NotImplementedError end |
#custom_validation? ⇒ Boolean
47 48 49 |
# File 'lib/action_spec/schema/base.rb', line 47 def custom_validation? false end |
#materialize_missing(context:, coerce:, result:, path:) ⇒ Object
23 24 25 |
# File 'lib/action_spec/schema/base.rb', line 23 def materialize_missing(context:, coerce:, result:, path:) Schema::Missing end |
#validate_constraints(value, result:, path:, field: nil, context: nil) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/action_spec/schema/base.rb', line 35 def validate_constraints(value, result:, path:, field: nil, context: nil) return if value.nil? validate_enum(value, result:, path:, field:, context:) validate_range(value, result:, path:, field:, context:) validate_pattern(value, result:, path:, field:, context:) end |