Class: GraphqlDevise::MountMethod::OptionSanitizers::ArrayChecker
- Inherits:
-
Object
- Object
- GraphqlDevise::MountMethod::OptionSanitizers::ArrayChecker
- Defined in:
- lib/graphql_devise/mount_method/option_sanitizers/array_checker.rb
Instance Method Summary collapse
- #call!(value, key) ⇒ Object
-
#initialize(element_type) ⇒ ArrayChecker
constructor
A new instance of ArrayChecker.
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 |