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 collapse

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.



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

def initialize(attribute_name, options = {})
  super

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

  skip_condition.default_to_allowing_nil!
end

Instance Attribute Details

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

Returns:

  • (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