Class: Sekisyo::Validators::ArrayValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/sekisyo/validators/array_validator.rb

Overview

Sekisyo Validators ArrayValidator is a validator that accepts only array value.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, options = {}) ⇒ ArrayValidator

Returns a new instance of ArrayValidator.



9
10
11
12
13
14
15
16
17
# File 'lib/sekisyo/validators/array_validator.rb', line 9

def initialize(key, options = {})
  @key = key
  @options = options

  @items_options = @options.fetch('items', {})
  items_validator_class = Sekisyo::Validator::VALIDATORS[@items_options.delete('type')]
  items_validator_class ||= Sekisyo::Validators::AnyValidator
  @items_validator = items_validator_class.new(nil, @items_options)
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



19
20
21
# File 'lib/sekisyo/validators/array_validator.rb', line 19

def key
  @key
end

Instance Method Details

#valid?(value) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
24
25
26
27
28
# File 'lib/sekisyo/validators/array_validator.rb', line 21

def valid?(value)
  type_validate(value) &&
    presence_validate(value) &&
    bytesize_validate(value) &&
    min_size_validate(value) &&
    max_size_validate(value) &&
    items_validate(value)
end