Class: Validation::Rule::Matches
- Inherits:
-
Object
- Object
- Validation::Rule::Matches
- Defined in:
- lib/validation/rule/matches.rb
Overview
Matches rule
Instance Attribute Summary collapse
-
#obj ⇒ Object
writeonly
Sets the attribute obj.
Instance Method Summary collapse
-
#error_key ⇒ Object
The error key for this rule.
-
#initialize(matcher_field) ⇒ Matches
constructor
This class should take the field to match with in the constructor:.
-
#params ⇒ Object
Params is the matcher_field given in the constructor.
-
#valid_value?(value) ⇒ Boolean
Determines if value matches the field given in the constructor.
Constructor Details
#initialize(matcher_field) ⇒ Matches
This class should take the field to match with in the constructor:
rule = Validation::Rule::Matches(:password) rule.obj = OpenStruct.new(:password => ‘foo’) rule.valid_value?(‘foo’)
12 13 14 |
# File 'lib/validation/rule/matches.rb', line 12 def initialize(matcher_field) @matcher_field = matcher_field end |
Instance Attribute Details
#obj=(value) ⇒ Object (writeonly)
Sets the attribute obj
5 6 7 |
# File 'lib/validation/rule/matches.rb', line 5 def obj=(value) @obj = value end |
Instance Method Details
#error_key ⇒ Object
The error key for this rule
17 18 19 |
# File 'lib/validation/rule/matches.rb', line 17 def error_key :matches end |
#params ⇒ Object
Params is the matcher_field given in the constructor
22 23 24 |
# File 'lib/validation/rule/matches.rb', line 22 def params @matcher_field end |
#valid_value?(value) ⇒ Boolean
Determines if value matches the field given in the constructor
27 28 29 30 |
# File 'lib/validation/rule/matches.rb', line 27 def valid_value?(value) matcher_value = @obj.send(@matcher_field) matcher_value == value end |