Class: WhyValidationsSuckIn96::ValidatesDate
- Inherits:
-
Validation
- Object
- Validation
- WhyValidationsSuckIn96::ValidatesDate
- Includes:
- AttributeBasedValidation, SkippableValidation
- Defined in:
- lib/whyvalidationssuckin96/macros/validates_date.rb
Overview
Checks the validity of an date attribute against a regular expression.
Constant Summary collapse
- DefaultDelimiters =
%r{[-/]}
- DefaultParser =
lambda do |str| month, day, year = str.split(DefaultDelimiters, 3) {:month => month, :day => day, :year => year} end
- DefaultOptions =
{ :message => "does not match the given date format or is not a valid date", :parser => DefaultParser }
Instance Attribute Summary collapse
-
#date ⇒ Object
readonly
Returns the value of attribute date.
Attributes inherited from Validation
Instance Method Summary collapse
-
#initialize(validatable, options = {}) ⇒ ValidatesDate
constructor
A new instance of ValidatesDate.
- #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 = {}) ⇒ ValidatesDate
Returns a new instance of ValidatesDate.
32 33 34 |
# File 'lib/whyvalidationssuckin96/macros/validates_date.rb', line 32 def initialize(validatable, = {}) super end |
Instance Attribute Details
#date ⇒ Object (readonly)
Returns the value of attribute date.
14 15 16 |
# File 'lib/whyvalidationssuckin96/macros/validates_date.rb', line 14 def date @date end |
Instance Method Details
#validate ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/whyvalidationssuckin96/macros/validates_date.rb', line 36 def validate super if parse_date pass else fail end rescue => e fail end |