Class: Aequitas::Rule::Confirmation

Inherits:
Aequitas::Rule show all
Defined in:
lib/aequitas/rule/confirmation.rb

Instance Attribute Summary (collapse)

Attributes inherited from Aequitas::Rule

#attribute_name, #custom_message, #guard, #skip_condition

Attributes included from ValueObject

#equalizer

Instance Method Summary (collapse)

Methods inherited from Aequitas::Rule

#attribute_value, #execute?, rules_for, #skip?, #violation_data, #violation_info, #violation_values

Methods included from ValueObject

#equalize_on

Constructor Details

- (Confirmation) initialize(attribute_name, options = {})

Returns a new instance of Confirmation



13
14
15
16
17
18
19
20
21
22
# File 'lib/aequitas/rule/confirmation.rb', line 13

def initialize(attribute_name, options = {})
  super

  @confirmation_attribute_name = options.fetch(:confirm) do
    :#{attribute_name}_confirmation"
  end

  skip_condition.default_to_allowing_nil!
  skip_condition.default_to_allowing_blank!
end

Instance Attribute Details

- (Object) confirmation_attribute_name (readonly)

Returns the value of attribute confirmation_attribute_name



11
12
13
# File 'lib/aequitas/rule/confirmation.rb', line 11

def confirmation_attribute_name
  @confirmation_attribute_name
end

Instance Method Details

- (Object) confirmation_value(resource)



34
35
36
# File 'lib/aequitas/rule/confirmation.rb', line 34

def confirmation_value(resource)
  resource.instance_variable_get("@#{@confirmation_attribute_name}")
end

- (Object) validate(resource)



24
25
26
27
28
29
30
31
32
# File 'lib/aequitas/rule/confirmation.rb', line 24

def validate(resource)
  value = attribute_value(resource)

  if skip?(value) || value == confirmation_value(resource)
    nil
  else
    new_violation(resource, value)
  end
end

- (Object) violation_type



38
39
40
# File 'lib/aequitas/rule/confirmation.rb', line 38

def violation_type
  :confirmation
end