Class: Central::Devtools::Config::TypeCheck

Inherits:
Object
  • Object
show all
Defined in:
lib/central/devtools/config.rb

Overview

Simple named type check representation

Constant Summary collapse

FORMAT_ERROR =
'%<name>s: Got instance of %<got>s expected %<allowed>s'.freeze
CLASS_DELIM =
','.freeze

Instance Method Summary collapse

Instance Method Details

#call(value) ⇒ Object

Check value for instance of expected class

Parameters:

  • value (Object)

Returns:

  • (Object)


24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/central/devtools/config.rb', line 24

def call(value)
  klass = value.class

  unless allowed_classes.any?(&klass.method(:equal?))
    fail TypeError, FORMAT_ERROR % {
      name: name,
      got: klass,
      allowed: allowed_classes.join(CLASS_DELIM)
    }
  end

  value
end