Class: GraphqlDevise::MountMethod::OptionSanitizers::ArrayChecker

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

Instance Method Summary collapse

Constructor Details

#initialize(element_type) ⇒ ArrayChecker

Returns a new instance of ArrayChecker.



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

def initialize(element_type)
  @element_type  = element_type
  @default_value = []
end

Instance Method Details

#call!(value, key) ⇒ Object



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

def call!(value, key)
  return @default_value if value.blank?

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

  unless value.all? { |element| element.instance_of?(@element_type) }
    raise InvalidMountOptionsError, "`#{key}` option has invalid elements. #{@element_type} expected."
  end

  value
end