Sha256: 19b600260b4376a78275ec3cc193f47071e52a6e72606c90a6a57028bd8ce7c1

Contents?: true

Size: 823 Bytes

Versions: 5

Compression:

Stored size: 823 Bytes

Contents

class InputSanitizer::V2::CleanField < MethodStruct.new(:data, :has_key, :default, :collection, :type, :converter, :options)
  def call
    if has_key
      convert
    elsif default
      converter.call(default, options)
    elsif options[:required]
      raise InputSanitizer::ValueMissingError
    else
      raise InputSanitizer::OptionalValueOmitted
    end
  end

  private
  def convert
    if collection
      collection_clean.call(
        :data => data,
        :collection => collection,
        :converter => converter,
        :options => options
      )
    else
      converter.call(data, options)
    end
  end

  def collection_clean
    case type
    when :payload
      InputSanitizer::V2::CleanPayloadCollectionField
    when :query
      InputSanitizer::V2::CleanQueryCollectionField
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
input_sanitizer-0.6.0 lib/input_sanitizer/v2/clean_field.rb
input_sanitizer-0.5.0 lib/input_sanitizer/v2/clean_field.rb
input_sanitizer-0.4.1 lib/input_sanitizer/v2/clean_field.rb
input_sanitizer-0.4.0 lib/input_sanitizer/v2/clean_field.rb
input_sanitizer-0.3.33 lib/input_sanitizer/v2/clean_field.rb