Class: Aequitas::Rule::Acceptance
- Inherits:
-
Aequitas::Rule
- Object
- Aequitas::Rule
- Aequitas::Rule::Acceptance
- Defined in:
- lib/aequitas/rule/acceptance.rb
Overview
TODO: update this to inherit from Rule::Within::Set
Constant Summary collapse
- DEFAULT_ACCEPTED_VALUES =
[ '1', 1, 'true', true, 't' ]
Instance Attribute Summary collapse
-
#accept ⇒ Object
readonly
Returns the value of attribute accept.
Attributes inherited from Aequitas::Rule
#attribute_name, #custom_message, #guard, #skip_condition
Attributes included from ValueObject
Instance Method Summary collapse
-
#initialize(attribute_name, options = {}) ⇒ Acceptance
constructor
A new instance of Acceptance.
- #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 = {}) ⇒ Acceptance
Returns a new instance of Acceptance.
16 17 18 19 20 21 22 |
# File 'lib/aequitas/rule/acceptance.rb', line 16 def initialize(attribute_name, = {}) super @accept = Array(.fetch(:accept, DEFAULT_ACCEPTED_VALUES)) skip_condition.default_to_allowing_nil! end |
Instance Attribute Details
#accept ⇒ Object (readonly)
Returns the value of attribute accept.
14 15 16 |
# File 'lib/aequitas/rule/acceptance.rb', line 14 def accept @accept end |
Instance Method Details
#valid?(resource) ⇒ Boolean
24 25 26 27 28 |
# File 'lib/aequitas/rule/acceptance.rb', line 24 def valid?(resource) value = attribute_value(resource) skip?(value) || accept.include?(value) end |
#violation_type(resource) ⇒ Object
30 31 32 |
# File 'lib/aequitas/rule/acceptance.rb', line 30 def violation_type(resource) :accepted end |