Class: Validatable::ValidatesLengthOf
- Inherits:
-
ValidationBase
- Object
- ValidationBase
- Validatable::ValidatesLengthOf
- Defined in:
- lib/validatable/validations/validates_length_of.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#in ⇒ Object
Returns the value of attribute in.
-
#is ⇒ Object
Returns the value of attribute is.
-
#maximum ⇒ Object
Returns the value of attribute maximum.
-
#minimum ⇒ Object
Returns the value of attribute minimum.
Attributes inherited from ValidationBase
#after_validate, #allow_blank, #allow_nil, #attribute, #if, #klass
Instance Method Summary collapse
Methods inherited from ValidationBase
Constructor Details
This class inherits a constructor from Validatable::ValidationBase
Instance Attribute Details
#in ⇒ Object
Returns the value of attribute in.
3 4 5 |
# File 'lib/validatable/validations/validates_length_of.rb', line 3 def in @in end |
#is ⇒ Object
Returns the value of attribute is.
3 4 5 |
# File 'lib/validatable/validations/validates_length_of.rb', line 3 def is @is end |
#maximum ⇒ Object
Returns the value of attribute maximum.
3 4 5 |
# File 'lib/validatable/validations/validates_length_of.rb', line 3 def maximum @maximum end |
#minimum ⇒ Object
Returns the value of attribute minimum.
3 4 5 |
# File 'lib/validatable/validations/validates_length_of.rb', line 3 def minimum @minimum end |
Instance Method Details
#message(instance) ⇒ Object
5 6 7 |
# File 'lib/validatable/validations/validates_length_of.rb', line 5 def (instance) super || "is invalid" end |
#valid?(instance) ⇒ Boolean
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/validatable/validations/validates_length_of.rb', line 9 def valid?(instance) valid = true value = instance.send(self.attribute) if value.nil? return true if allow_nil value = '' end if !value or (value.respond_to?(:empty?) and value.empty?) return true if allow_blank value = '' end valid &&= value.length <= maximum unless maximum.nil? valid &&= value.length >= minimum unless minimum.nil? valid &&= value.length == is unless is.nil? valid &&= self.in.include?(value.length) unless self.in.nil? valid end |