Class: Aequitas::Rule::Acceptance

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

Overview

TODO: update this to inherit from Rule::Within::Set

Constant Summary

DEFAULT_ACCEPTED_VALUES =
[ '1', 1, 'true', true, 't' ]

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 = {}) ⇒ Acceptance

Returns a new instance of Acceptance



17
18
19
20
21
22
23
# File 'lib/aequitas/rule/acceptance.rb', line 17

def initialize(attribute_name, options = {})
  super

  @accept = Array(options.fetch(:accept, DEFAULT_ACCEPTED_VALUES)).to_set

  skip_condition.default_to_allowing_nil!
end

Instance Attribute Details

#acceptObject (readonly)

Returns the value of attribute accept



15
16
17
# File 'lib/aequitas/rule/acceptance.rb', line 15

def accept
  @accept
end

Instance Method Details

#valid_value?(value) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/aequitas/rule/acceptance.rb', line 25

def valid_value?(value)
  skip?(value) || accept.include?(value)
end

#violation_typeObject



29
30
31
# File 'lib/aequitas/rule/acceptance.rb', line 29

def violation_type
  :accepted
end