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?, #validate, #violation_data, #violation_info, #violation_values

Methods included from ValueObject

#equalize_on

Constructor Details

#initialize(attribute_name, options = {}) ⇒ Confirmation

Returns a new instance of Confirmation.



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

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

#confirmation_attribute_nameObject (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

#confirmation_value(resource) ⇒ Object



31
32
33
# File 'lib/aequitas/rule/confirmation.rb', line 31

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

#valid?(resource) ⇒ Boolean

Returns:

  • (Boolean)


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

def valid?(resource)
  value = attribute_value(resource)

  skip?(value) || value == confirmation_value(resource)
end

#violation_type(resource) ⇒ Object



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

def violation_type(resource)
  :confirmation
end