Class: UniformArrayValidation

Inherits:
Validation show all
Defined in:
lib/json_patterns.rb

Constant Summary

Constants included from Inspectable

Inspectable::INSPECTING_KEY

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Validation

#as_object_members, #expects_an_object?, memoized_new_from_pattern, new_from_pattern, #validate_from_root

Methods included from HashInitialized

#initialize

Methods included from DeepEquality

#==

Methods included from Inspectable

#inspect

Instance Attribute Details

#value_validationObject

Returns the value of attribute value_validation.



433
434
435
# File 'lib/json_patterns.rb', line 433

def value_validation
  @value_validation
end

Instance Method Details

#shallow_describeObject



451
452
453
# File 'lib/json_patterns.rb', line 451

def shallow_describe
  Set['array']
end

#shallow_match?(data) ⇒ Boolean

Returns:



447
448
449
# File 'lib/json_patterns.rb', line 447

def shallow_match?(data)
  data.is_a? Array
end

#to_sObject



455
456
457
# File 'lib/json_patterns.rb', line 455

def to_s
  "[ #{@value_validation}, ... ]"
end

#validate(path, data) ⇒ Object



435
436
437
438
439
440
441
442
443
444
445
# File 'lib/json_patterns.rb', line 435

def validate(path, data)
  if data.is_a? Array
    return validate_members(path, data)
  else
    return [ValidationUnexpected.new(
      path: path,
      expected: 'array',
      found: json_type_name(data),
    )]
  end
end