Sha256: 579bf092650854bb5a7599d8548ee04a1ee63cc639496038e8eaccdbc053eb4a

Contents?: true

Size: 742 Bytes

Versions: 9

Compression:

Stored size: 742 Bytes

Contents

module GraphqlDevise
  module MountMethod
    module OptionSanitizers
      class ArrayChecker
        def initialize(element_type)
          @element_type  = element_type
          @default_value = []
        end

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

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

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

          value
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
graphql_devise-0.12.3 lib/graphql_devise/mount_method/option_sanitizers/array_checker.rb
graphql_devise-0.12.2 lib/graphql_devise/mount_method/option_sanitizers/array_checker.rb
graphql_devise-0.12.1 lib/graphql_devise/mount_method/option_sanitizers/array_checker.rb
graphql_devise-0.12.0 lib/graphql_devise/mount_method/option_sanitizers/array_checker.rb
graphql_devise-0.11.4 lib/graphql_devise/mount_method/option_sanitizers/array_checker.rb
graphql_devise-0.11.3 lib/graphql_devise/mount_method/option_sanitizers/array_checker.rb
graphql_devise-0.11.2 lib/graphql_devise/mount_method/option_sanitizers/array_checker.rb
graphql_devise-0.11.1 lib/graphql_devise/mount_method/option_sanitizers/array_checker.rb
graphql_devise-0.11.0 lib/graphql_devise/mount_method/option_sanitizers/array_checker.rb