Sha256: e2c0fa7425508fc7e584611e8c318772c79c39c7a6ef88d9cc828167f57fb9af

Contents?: true

Size: 674 Bytes

Versions: 1

Compression:

Stored size: 674 Bytes

Contents

class InputSanitizer::V2::NestedSanitizerFactory
  class NilAllowed
    def cleaned
      nil
    end

    def valid?
      true
    end
  end
  
  class HashExpected
    def initialize(value)
      @value = value
    end
    
    def valid?
      false
    end
    
    def cleaned
      nil
    end
    
    def errors
      [InputSanitizer::TypeMismatchError.new(@value, :hash)]
    end
  end

  def self.for(nested_sanitizer_klass, value, options)
    if value.nil? && options[:allow_nil] && !options[:collection]
      NilAllowed.new
    elsif !value.is_a?(Hash)
      HashExpected.new(value)
    else
      nested_sanitizer_klass.new(value, options)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
input_sanitizer-0.6.0 lib/input_sanitizer/v2/nested_sanitizer_factory.rb