Class: ApipieDSL::Validator::NestedValidator

Inherits:
BaseValidator show all
Defined in:
lib/apipie_dsl/validator.rb

Instance Attribute Summary

Attributes inherited from BaseValidator

#param_description

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseValidator

#==, #docs, find, inherited, #inspect, #inspected_fields, #merge_with, #to_s, #valid?

Constructor Details

#initialize(param_description, argument, param_group) ⇒ NestedValidator

Returns a new instance of NestedValidator.



444
445
446
447
448
# File 'lib/apipie_dsl/validator.rb', line 444

def initialize(param_description, argument, param_group)
  super(param_description)
  @validator = HashValidator.new(param_description, argument, param_group)
  @type = argument
end

Class Method Details

.build(param_description, argument, options, block) ⇒ Object



450
451
452
453
454
# File 'lib/apipie_dsl/validator.rb', line 450

def self.build(param_description, argument, options, block)
  return if argument != Array || !block.is_a?(Proc) || block.arity.positive?

  new(param_description, block, options[:param_group])
end

Instance Method Details

#descriptionObject



470
471
472
# File 'lib/apipie_dsl/validator.rb', line 470

def description
  'Must be an Array of nested elements'
end

#expected_typeObject



466
467
468
# File 'lib/apipie_dsl/validator.rb', line 466

def expected_type
  'array'
end

#sub_paramsObject



474
475
476
# File 'lib/apipie_dsl/validator.rb', line 474

def sub_params
  @validator.sub_params
end

#validate(value) ⇒ Object



456
457
458
459
460
461
462
463
464
# File 'lib/apipie_dsl/validator.rb', line 456

def validate(value)
  value ||= []
  return false if value.class != Array

  value.each do |child|
    return false unless @validator.validate(child)
  end
  true
end