Class: ActionSpec::Schema::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/action_spec/schema/base.rb

Direct Known Subclasses

ArrayOf, ObjectOf, Scalar

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options = {})
  options = options.symbolize_keys
  @default = options[:default]
  @enum = options[:enum]
  @range = options[:range]
  @pattern = options[:pattern]
  @length = options[:length]
  @blank = options.key?(:blank) ? options[:blank] : options.fetch(:allow_blank, true)
  @description = options[:desc] || options[:description]
  @example = options[:example]
  @examples = options[:examples]
end

Instance Attribute Details

#blankObject (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

#defaultObject (readonly)

Returns the value of attribute default.



6
7
8
# File 'lib/action_spec/schema/base.rb', line 6

def default
  @default
end

#descriptionObject (readonly)

Returns the value of attribute description.



6
7
8
# File 'lib/action_spec/schema/base.rb', line 6

def description
  @description
end

#enumObject (readonly)

Returns the value of attribute enum.



6
7
8
# File 'lib/action_spec/schema/base.rb', line 6

def enum
  @enum
end

#exampleObject (readonly)

Returns the value of attribute example.



6
7
8
# File 'lib/action_spec/schema/base.rb', line 6

def example
  @example
end

#examplesObject (readonly)

Returns the value of attribute examples.



6
7
8
# File 'lib/action_spec/schema/base.rb', line 6

def examples
  @examples
end

#lengthObject (readonly)

Returns the value of attribute length.



6
7
8
# File 'lib/action_spec/schema/base.rb', line 6

def length
  @length
end

#patternObject (readonly)

Returns the value of attribute pattern.



6
7
8
# File 'lib/action_spec/schema/base.rb', line 6

def pattern
  @pattern
end

#rangeObject (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

Returns:

  • (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

#copyObject

Raises:

  • (NotImplementedError)


43
44
45
# File 'lib/action_spec/schema/base.rb', line 43

def copy
  raise NotImplementedError
end

#custom_validation?Boolean

Returns:

  • (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