Class: WhyValidationsSuckIn96::ValidatesLength
- Inherits:
-
Validation
- Object
- Validation
- WhyValidationsSuckIn96::ValidatesLength
- Includes:
- AttributeBasedValidation, SkippableValidation
- Defined in:
- lib/whyvalidationssuckin96/macros/validates_length.rb
Overview
Checks the validity of an attribute against a given set of sizes.
Constant Summary collapse
- DefaultOptions =
{:message => "does not meet the given length restrictions"}
- ValidOptions =
[:is, :in, :minimum, :maximum]
- OptionIncompatibility =
{ :is => [:minimum, :maximum, :in], :in => [:minimum, :maximum, :is] }
Instance Attribute Summary
Attributes inherited from Validation
Instance Method Summary collapse
-
#initialize(validatable, options = {}) ⇒ ValidatesLength
constructor
A new instance of ValidatesLength.
- #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 = {}) ⇒ ValidatesLength
Returns a new instance of ValidatesLength.
49 50 51 52 |
# File 'lib/whyvalidationssuckin96/macros/validates_length.rb', line 49 def initialize(validatable, = {}) super () end |
Instance Method Details
#validate ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/whyvalidationssuckin96/macros/validates_length.rb', line 54 def validate super fail unless attribute_value.respond_to?(:size) all_valid = ValidOptions.collect do |opt_name| next(true) if [opt_name].nil? send(:"validate_#{opt_name}") end.all? all_valid ? pass : fail end |