Class: ReeValidator::ValidateInclusion

Inherits:
Object
  • Object
show all
Includes:
Ree::FnDSL
Defined in:
lib/ree_lib/packages/ree_validator/package/ree_validator/functions/validate_inclusion.rb

Constant Summary collapse

InclusionErr =
Class.new(StandardError)

Instance Method Summary collapse

Instance Method Details

#call(value, list_or_set, error = nil) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ree_lib/packages/ree_validator/package/ree_validator/functions/validate_inclusion.rb', line 17

def call(value, list_or_set, error = nil)
  if !list_or_set.include?(value)
    error ||= InclusionErr.new(
      t(
        'validator.inclusion.error',
        {list: list_or_set.to_a},
        default_by_locale: :en
      )
    )

    raise error
  end

  true
end