Class: DisjunctionValidation

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

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

#alternativesObject

TODO: Do this as a separate transformation step when compiling the validation



347
348
349
# File 'lib/json_patterns.rb', line 347

def alternatives
  @alternatives
end

Instance Method Details

#as_object_membersObject



377
378
379
380
381
# File 'lib/json_patterns.rb', line 377

def as_object_members
  ObjectMembersDisjunctionValidation.new(
    alternatives: @alternatives.map { |v| v.as_object_members }
  )
end

#concrete_validationObject



367
368
369
370
371
# File 'lib/json_patterns.rb', line 367

def concrete_validation
  @concrete_validation ||= expects_an_object? ?
    ObjectValidation.new(members: as_object_members) :
    ValueDisjunctionValidation.new(alternatives: @alternatives)
end

#expects_an_object?Boolean

Returns:



373
374
375
# File 'lib/json_patterns.rb', line 373

def expects_an_object?
  @alternatives.all? { |v| v.expects_an_object? }
end

#shallow_describeObject



359
360
361
# File 'lib/json_patterns.rb', line 359

def shallow_describe
  concrete_validation.shallow_describe
end

#shallow_match?(data) ⇒ Boolean

Returns:



355
356
357
# File 'lib/json_patterns.rb', line 355

def shallow_match?(data)
  concrete_validation.shallow_match?(data)
end

#to_sObject



363
364
365
# File 'lib/json_patterns.rb', line 363

def to_s
  concrete_validation.to_s
end

#validate(path, data) ⇒ Object

TODO: Use some sort of delegator to handle these methods?



351
352
353
# File 'lib/json_patterns.rb', line 351

def validate(path, data)
  concrete_validation.validate(path, data)
end