Class: AFCSalesforce::Tools::Validation::Rule::Matches
- Inherits:
-
Object
- Object
- AFCSalesforce::Tools::Validation::Rule::Matches
- Defined in:
- lib/afc_salesforce/tools/validation/rule/matches.rb
Overview
Matches rule
Instance Attribute Summary collapse
-
#obj ⇒ Object
writeonly
Sets the attribute obj.
Instance Method Summary collapse
- #error(value) ⇒ Object
-
#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’)
14 15 16 |
# File 'lib/afc_salesforce/tools/validation/rule/matches.rb', line 14 def initialize(matcher_field) @matcher_field = matcher_field end |
Instance Attribute Details
#obj=(value) ⇒ Object (writeonly)
Sets the attribute obj
7 8 9 |
# File 'lib/afc_salesforce/tools/validation/rule/matches.rb', line 7 def obj=(value) @obj = value end |
Instance Method Details
#error(value) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/afc_salesforce/tools/validation/rule/matches.rb', line 23 def error(value) results = {} results[:expected] = value results[:got] = @obj.send(@matcher_field) results end |
#error_key ⇒ Object
The error key for this rule
19 20 21 |
# File 'lib/afc_salesforce/tools/validation/rule/matches.rb', line 19 def error_key :matches end |
#params ⇒ Object
Params is the matcher_field given in the constructor
31 32 33 |
# File 'lib/afc_salesforce/tools/validation/rule/matches.rb', line 31 def params @matcher_field end |
#valid_value?(value) ⇒ Boolean
Determines if value matches the field given in the constructor
36 37 38 39 |
# File 'lib/afc_salesforce/tools/validation/rule/matches.rb', line 36 def valid_value?(value) matcher_value = @obj.send(@matcher_field) matcher_value == value end |