Class: Predicates::SameAs
Overview
Requires that one field must be the same as another field. Useful when combined with virtual attributes to describe things like password or email confirmation.
Options
Example
field_is_same_as :method => :other_field
Instance Attribute Summary collapse
-
#method ⇒ Object
Returns the value of attribute method.
Attributes inherited from Base
#full_message, #or_empty, #validate_if, #validate_on
Instance Method Summary collapse
Methods inherited from Base
#allow_empty?, #error, #error_binds, #initialize, #normalize, #to_human
Constructor Details
This class inherits a constructor from Predicates::Base
Instance Attribute Details
#method ⇒ Object
Returns the value of attribute method.
8 9 10 |
# File 'lib/predicates/same_as.rb', line 8 def method @method end |
Instance Method Details
#error_message ⇒ Object
10 11 12 |
# File 'lib/predicates/same_as.rb', line 10 def @error_message ||= :same_as end |
#validate(value, record) ⇒ Object
14 15 16 |
# File 'lib/predicates/same_as.rb', line 14 def validate(value, record) value == record.send(self.method) end |