Class: EasyJSONMatcher::ArrayValidator
- Inherits:
-
Validator
- Object
- Validator
- EasyJSONMatcher::ArrayValidator
show all
- Defined in:
- lib/easy_json_matcher/array_validator.rb
Instance Attribute Summary collapse
Attributes inherited from Validator
#content, #errors, #key, #required
Instance Method Summary
collapse
Methods inherited from Validator
#_check_content_type, #_check_required?, #_create_validator, #_no_errors?, #_post_initialise, #_set_content, #get_errors, #initialize, #reset!, #valid?
Instance Attribute Details
#validator_results ⇒ Object
Returns the value of attribute validator_results.
4
5
6
|
# File 'lib/easy_json_matcher/array_validator.rb', line 4
def validator_results
@validator_results
end
|
#validators ⇒ Object
Returns the value of attribute validators.
4
5
6
|
# File 'lib/easy_json_matcher/array_validator.rb', line 4
def validators
@validators
end
|
Instance Method Details
#_accumulate_errors(validator) ⇒ Object
69
70
71
72
73
74
|
# File 'lib/easy_json_matcher/array_validator.rb', line 69
def _accumulate_errors(validator)
content.each do |candidate|
_run_validator(validator, candidate)
end
errors << validator.errors unless validator._no_errors?
end
|
#_add_validator(validator) ⇒ Object
61
62
63
|
# File 'lib/easy_json_matcher/array_validator.rb', line 61
def _add_validator(validator)
validators << validator
end
|
#_clear_validators ⇒ Object
57
58
59
|
# File 'lib/easy_json_matcher/array_validator.rb', line 57
def _clear_validators
validators.clear
end
|
#_content_is_array? ⇒ Boolean
47
48
49
|
# File 'lib/easy_json_matcher/array_validator.rb', line 47
def _content_is_array?
content.is_a? Array
end
|
#_run_validator(validator, candidate) ⇒ Object
76
77
78
|
# File 'lib/easy_json_matcher/array_validator.rb', line 76
def _run_validator(validator, candidate)
validator.valid? candidate
end
|
#_validate ⇒ Object
Private methods #######################################
42
43
44
45
|
# File 'lib/easy_json_matcher/array_validator.rb', line 42
def _validate
errors << "#{content} is not an Array" unless _content_is_array?
_validate_content
end
|
#_validate_content ⇒ Object
51
52
53
54
55
|
# File 'lib/easy_json_matcher/array_validator.rb', line 51
def _validate_content
validators.each do |val|
_accumulate_errors val
end
end
|
#_validation_result ⇒ Object
80
81
82
|
# File 'lib/easy_json_matcher/array_validator.rb', line 80
def _validation_result
!validator_results.include? false
end
|
#should_only_contain(type:, opts: {}) ⇒ Object
35
36
37
38
|
# File 'lib/easy_json_matcher/array_validator.rb', line 35
def should_only_contain(type:,opts: {})
_clear_validators
_add_validator(_create_validator(type: type, opts: opts))
end
|
#should_only_contain_booleans(opts: {}) ⇒ Object
23
24
25
|
# File 'lib/easy_json_matcher/array_validator.rb', line 23
def should_only_contain_booleans(opts: {})
should_only_contain type: :boolean, opts: opts
end
|
#should_only_contain_dates(opts: {}) ⇒ Object
27
28
29
|
# File 'lib/easy_json_matcher/array_validator.rb', line 27
def should_only_contain_dates(opts: {})
should_only_contain type: :date, opts: opts
end
|
#should_only_contain_numbers(opts: {}) ⇒ Object
19
20
21
|
# File 'lib/easy_json_matcher/array_validator.rb', line 19
def should_only_contain_numbers(opts: {})
should_only_contain type: :number, opts: opts
end
|
#should_only_contain_objects(opts: {}) ⇒ Object
11
12
13
|
# File 'lib/easy_json_matcher/array_validator.rb', line 11
def should_only_contain_objects(opts: {})
should_only_contain type: :object, opts: opts
end
|
#should_only_contain_schema(name:, opts: {}) ⇒ Object
31
32
33
|
# File 'lib/easy_json_matcher/array_validator.rb', line 31
def should_only_contain_schema(name:, opts: {})
should_only_contain type: :schema, opts: opts.merge({name: name})
end
|
#should_only_contain_strings(opts: {}) ⇒ Object
Methods for requiring values by type #################
7
8
9
|
# File 'lib/easy_json_matcher/array_validator.rb', line 7
def should_only_contain_strings(opts: {})
should_only_contain type: :string, opts: opts
end
|
#should_only_contain_values(opts: {}) ⇒ Object
15
16
17
|
# File 'lib/easy_json_matcher/array_validator.rb', line 15
def should_only_contain_values(opts: {})
should_only_contain type: :value, opts: opts
end
|