Class: AFCSalesforce::Tools::Validation::Rule::Matches

Inherits:
Object
  • Object
show all
Defined in:
lib/afc_salesforce/tools/validation/rule/matches.rb

Overview

Matches rule

Instance Attribute Summary collapse

Instance Method Summary collapse

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

Parameters:

  • value

    the value to set the attribute obj to.



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_keyObject

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

#paramsObject

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

Returns:

  • (Boolean)


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