Class: ApipieDSL::Validator::BaseValidator
- Inherits:
-
Object
- Object
- ApipieDSL::Validator::BaseValidator
show all
- Defined in:
- lib/apipie_dsl/validator.rb
Overview
To create a new validator, inherit from ApipieDSL::Validator::BaseValidator and implement class method ‘build’ and instance method ‘validate’
Direct Known Subclasses
ArrayClassValidator, ArrayValidator, BooleanValidator, DecimalValidator, EnumValidator, HashValidator, NestedValidator, NumberValidator, ProcValidator, RegexpValidator, RestValidator, TypeValidator
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(param_description) ⇒ BaseValidator
Returns a new instance of BaseValidator.
25
26
27
|
# File 'lib/apipie_dsl/validator.rb', line 25
def initialize(param_description)
@param_description = param_description
end
|
Instance Attribute Details
#param_description ⇒ Object
Returns the value of attribute param_description.
23
24
25
|
# File 'lib/apipie_dsl/validator.rb', line 23
def param_description
@param_description
end
|
Class Method Details
.build(_param_description, _argument, _options, &_block) ⇒ Object
29
30
31
|
# File 'lib/apipie_dsl/validator.rb', line 29
def self.build(_param_description, _argument, _options, &_block)
raise NotImplementedError
end
|
.find(param_description, argument, options, block) ⇒ Object
56
57
58
59
60
61
62
|
# File 'lib/apipie_dsl/validator.rb', line 56
def self.find(param_description, argument, options, block)
@validators.each do |type|
validator = type.build(param_description, argument, options, block)
return validator if validator
end
nil
end
|
.inherited(subclass) ⇒ Object
51
52
53
54
|
# File 'lib/apipie_dsl/validator.rb', line 51
def self.inherited(subclass)
@validators ||= []
@validators.unshift(subclass)
end
|
Instance Method Details
#==(other) ⇒ Object
92
93
94
95
96
|
# File 'lib/apipie_dsl/validator.rb', line 92
def ==(other)
return false unless self.class == other.class
param_description == other.param_description
end
|
#description ⇒ Object
37
38
39
|
# File 'lib/apipie_dsl/validator.rb', line 37
def description
raise NotImplementedError
end
|
#docs ⇒ Object
74
75
76
|
# File 'lib/apipie_dsl/validator.rb', line 74
def docs
raise NotImplementedError
end
|
#expected_type ⇒ Object
78
79
80
|
# File 'lib/apipie_dsl/validator.rb', line 78
def expected_type
'string'
end
|
#inspect ⇒ Object
45
46
47
48
49
|
# File 'lib/apipie_dsl/validator.rb', line 45
def inspect
string = "#<#{self.class.name}:#{object_id} "
fields = inspected_fields.map { |field| "#{field}: #{send(field)}" }
string << fields.join(', ') << '>'
end
|
#inspected_fields ⇒ Object
41
42
43
|
# File 'lib/apipie_dsl/validator.rb', line 41
def inspected_fields
[:param_description]
end
|
#merge_with(other_validator) ⇒ Object
86
87
88
89
90
|
# File 'lib/apipie_dsl/validator.rb', line 86
def merge_with(other_validator)
return self if self == other_validator
raise NotImplementedError, "Don't know how to merge #{inspect} with #{other_validator.inspect}"
end
|
#sub_params ⇒ Object
82
83
84
|
# File 'lib/apipie_dsl/validator.rb', line 82
def sub_params
nil
end
|
#to_s ⇒ Object
70
71
72
|
# File 'lib/apipie_dsl/validator.rb', line 70
def to_s
description
end
|
#valid?(value) ⇒ Boolean
64
65
66
67
68
|
# File 'lib/apipie_dsl/validator.rb', line 64
def valid?(value)
return true if validate(value)
raise ParamInvalid.new(@param_description.name, value, description)
end
|
#validate(_value) ⇒ Object
33
34
35
|
# File 'lib/apipie_dsl/validator.rb', line 33
def validate(_value)
raise NotImplementedError
end
|