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.
26
27
28
|
# File 'lib/apipie_dsl/validator.rb', line 26
def initialize(param_description)
@param_description = param_description
end
|
Instance Attribute Details
#param_description ⇒ Object
Returns the value of attribute param_description.
24
25
26
|
# File 'lib/apipie_dsl/validator.rb', line 24
def param_description
@param_description
end
|
Class Method Details
.build(_param_description, _argument, _options, &_block) ⇒ Object
30
31
32
|
# File 'lib/apipie_dsl/validator.rb', line 30
def self.build(_param_description, _argument, _options, &_block)
raise NotImplementedError
end
|
.find(param_description, argument, options, block) ⇒ Object
58
59
60
61
62
63
64
|
# File 'lib/apipie_dsl/validator.rb', line 58
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
52
53
54
55
56
|
# File 'lib/apipie_dsl/validator.rb', line 52
def self.inherited(subclass)
super(subclass)
@validators ||= []
@validators.unshift(subclass)
end
|
Instance Method Details
#==(other) ⇒ Object
94
95
96
97
98
|
# File 'lib/apipie_dsl/validator.rb', line 94
def ==(other)
return false unless self.class == other.class
param_description == other.param_description
end
|
#description ⇒ Object
38
39
40
|
# File 'lib/apipie_dsl/validator.rb', line 38
def description
raise NotImplementedError
end
|
#docs ⇒ Object
76
77
78
|
# File 'lib/apipie_dsl/validator.rb', line 76
def docs
raise NotImplementedError
end
|
#expected_type ⇒ Object
80
81
82
|
# File 'lib/apipie_dsl/validator.rb', line 80
def expected_type
'string'
end
|
#inspect ⇒ Object
46
47
48
49
50
|
# File 'lib/apipie_dsl/validator.rb', line 46
def inspect
string = "#<#{self.class.name}:#{object_id} "
fields = inspected_fields.map { |field| "#{field}: #{send(field)}" }
string << fields.join(', ') << '>'
end
|
#inspected_fields ⇒ Object
42
43
44
|
# File 'lib/apipie_dsl/validator.rb', line 42
def inspected_fields
[:param_description]
end
|
#merge_with(other_validator) ⇒ Object
88
89
90
91
92
|
# File 'lib/apipie_dsl/validator.rb', line 88
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
84
85
86
|
# File 'lib/apipie_dsl/validator.rb', line 84
def sub_params
nil
end
|
#to_s ⇒ Object
72
73
74
|
# File 'lib/apipie_dsl/validator.rb', line 72
def to_s
description
end
|
#valid?(value) ⇒ Boolean
66
67
68
69
70
|
# File 'lib/apipie_dsl/validator.rb', line 66
def valid?(value)
return true if validate(value)
raise ParamInvalid.new(@param_description.name, value, description)
end
|
#validate(_value) ⇒ Object
34
35
36
|
# File 'lib/apipie_dsl/validator.rb', line 34
def validate(_value)
raise NotImplementedError
end
|