Class: Predicates::SameAs

Inherits:
Base
  • Object
show all
Defined in:
lib/predicates/same_as.rb

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

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

#methodObject

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_messageObject



10
11
12
# File 'lib/predicates/same_as.rb', line 10

def error_message
  @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