Class: Compel::Validators::Base
- Inherits:
-
Object
- Object
- Compel::Validators::Base
- Defined in:
- lib/compel/validators/base.rb
Direct Known Subclasses
ArrayItemsValidator, ArrayValidator, HashKeysValidator, HashValidator, TypeValidator
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#input ⇒ Object
readonly
Returns the value of attribute input.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(input, schema) ⇒ Base
constructor
A new instance of Base.
- #valid? ⇒ Boolean
Constructor Details
#initialize(input, schema) ⇒ Base
Returns a new instance of Base.
11 12 13 14 15 16 |
# File 'lib/compel/validators/base.rb', line 11 def initialize(input, schema) @input = input.nil? ? schema.default_value : input @schema = schema @output = nil @errors = [] end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
6 7 8 |
# File 'lib/compel/validators/base.rb', line 6 def errors @errors end |
#input ⇒ Object (readonly)
Returns the value of attribute input.
6 7 8 |
# File 'lib/compel/validators/base.rb', line 6 def input @input end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
6 7 8 |
# File 'lib/compel/validators/base.rb', line 6 def output @output end |
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
6 7 8 |
# File 'lib/compel/validators/base.rb', line 6 def schema @schema end |
Class Method Details
.validate(input, schema) ⇒ Object
22 23 24 |
# File 'lib/compel/validators/base.rb', line 22 def self.validate(input, schema) new(input, schema).validate end |
Instance Method Details
#valid? ⇒ Boolean
18 19 20 |
# File 'lib/compel/validators/base.rb', line 18 def valid? @errors.empty? end |