Class: Aequitas::Rule::Confirmation
- Inherits:
-
Aequitas::Rule
- Object
- Aequitas::Rule
- Aequitas::Rule::Confirmation
- Defined in:
- lib/aequitas/rule/confirmation.rb
Instance Attribute Summary collapse
-
#confirmation_attribute_name ⇒ Object
readonly
Returns the value of attribute confirmation_attribute_name.
Attributes inherited from Aequitas::Rule
#attribute_name, #custom_message, #guard, #skip_condition
Attributes included from ValueObject
Instance Method Summary collapse
- #confirmation_value(resource) ⇒ Object
-
#initialize(attribute_name, options = {}) ⇒ Confirmation
constructor
A new instance of Confirmation.
- #valid?(resource) ⇒ Boolean
- #violation_type(resource) ⇒ Object
Methods inherited from Aequitas::Rule
#attribute_value, #execute?, rules_for, #skip?, #validate, #violation_data, #violation_info, #violation_values
Methods included from ValueObject
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, = {}) super @confirmation_attribute_name = .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_name ⇒ Object (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
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 |