Class: GraphqlDevise::MountMethod::OptionSanitizers::ClassChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql_devise/mount_method/option_sanitizers/class_checker.rb

Instance Method Summary collapse

Constructor Details

#initialize(klass) ⇒ ClassChecker

Returns a new instance of ClassChecker.



7
8
9
# File 'lib/graphql_devise/mount_method/option_sanitizers/class_checker.rb', line 7

def initialize(klass)
  @klass_array = Array(klass)
end

Instance Method Details

#call!(value, key) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/graphql_devise/mount_method/option_sanitizers/class_checker.rb', line 11

def call!(value, key)
  return if value.nil?

  unless value.instance_of?(Class)
    raise InvalidMountOptionsError, "`#{key}` option has an invalid value. Class expected."
  end

  unless @klass_array.any? { |klass| value.ancestors.include?(klass) }
    raise InvalidMountOptionsError,
          "`#{key}` option has an invalid value. #{@klass_array.join(', ')} or descendants expected. Got #{value}."
  end

  value
end