Class: WhyValidationsSuckIn96::ValidatesFormat
- Inherits:
-
Validation
- Object
- Validation
- WhyValidationsSuckIn96::ValidatesFormat
- Includes:
- AttributeBasedValidation, SkippableValidation
- Defined in:
- lib/whyvalidationssuckin96/macros/validates_format.rb
Overview
Checks the validity of an attribute against a regular expression.
Constant Summary collapse
- DefaultOptions =
{:message => "does not match the given format"}
Instance Attribute Summary
Attributes inherited from Validation
Instance Method Summary collapse
-
#initialize(validatable, options = {}) ⇒ ValidatesFormat
constructor
A new instance of ValidatesFormat.
- #validate ⇒ Object
Methods included from AttributeBasedValidation
#attribute, #attribute_value, #validates?
Methods inherited from Validation
#failed?, #has_run?, #message, new_subclass, #passed?, #validates?
Constructor Details
#initialize(validatable, options = {}) ⇒ ValidatesFormat
Returns a new instance of ValidatesFormat.
21 22 23 24 |
# File 'lib/whyvalidationssuckin96/macros/validates_format.rb', line 21 def initialize(validatable, = {}) super raise(ArgumentError, "Regular expression to check against must be given as :with") unless [:with] end |
Instance Method Details
#validate ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/whyvalidationssuckin96/macros/validates_format.rb', line 26 def validate super if attribute_value.to_s =~ [:with] pass else fail end end |