Class: HashValidator::Validator::Base
- Inherits:
-
Object
- Object
- HashValidator::Validator::Base
- Defined in:
- lib/hash_validator/validators/base.rb
Direct Known Subclasses
ArrayValidator, BooleanValidator, ClassValidator, EmailValidator, EnumerableValidator, HashValidator, LambdaValidator, ManyValidator, MultipleValidator, OptionalValidator, PresenceValidator, RegexpValidator, SimpleValidator
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(name) ⇒ Base
constructor
A new instance of Base.
- #presence_error_message ⇒ Object
- #should_validate?(name) ⇒ Boolean
- #validate ⇒ Object
Constructor Details
#initialize(name) ⇒ Base
Returns a new instance of Base.
5 6 7 8 9 10 11 |
# File 'lib/hash_validator/validators/base.rb', line 5 def initialize(name) self.name = name.to_s unless self.name.size > 0 raise StandardError.new('Validator must be initialized with a valid name (length greater than zero)') end end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
2 3 4 |
# File 'lib/hash_validator/validators/base.rb', line 2 def name @name end |
Instance Method Details
#presence_error_message ⇒ Object
17 18 19 |
# File 'lib/hash_validator/validators/base.rb', line 17 def "#{self.name} required" end |
#should_validate?(name) ⇒ Boolean
13 14 15 |
# File 'lib/hash_validator/validators/base.rb', line 13 def should_validate?(name) self.name == name.to_s end |
#validate ⇒ Object
21 22 23 |
# File 'lib/hash_validator/validators/base.rb', line 21 def validate(*) raise StandardError.new('validate should not be called directly on BaseValidator') end |