Class: DisjunctionValidation
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
#initialize
#==
#inspect
Instance Attribute Details
#alternatives ⇒ Object
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_members ⇒ Object
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_validation ⇒ Object
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
373
374
375
|
# File 'lib/json_patterns.rb', line 373
def expects_an_object?
@alternatives.all? { |v| v.expects_an_object? }
end
|
#shallow_describe ⇒ Object
359
360
361
|
# File 'lib/json_patterns.rb', line 359
def shallow_describe
concrete_validation.shallow_describe
end
|
#shallow_match?(data) ⇒ Boolean
355
356
357
|
# File 'lib/json_patterns.rb', line 355
def shallow_match?(data)
concrete_validation.shallow_match?(data)
end
|
#to_s ⇒ Object
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
|