Sha256: d4183153f6a5a5a41749271d883dec64249a3a01cd5db58d5245ee983c48387f

Contents?: true

Size: 749 Bytes

Versions: 1

Compression:

Stored size: 749 Bytes

Contents

module Mutations
  class InputFilter
    @default_options = {}

    def self.default_options
      @default_options
    end

    attr_accessor :options

    def initialize(opts = {})
      self.options = (self.class.default_options || {}).merge(opts)
    end

    # returns -> [sanitized data, error]
    # If an error is returned, then data will be nil
    def filter(data)
      [data, nil]
    end

    def has_default?
      options.has_key?(:default)
    end

    def default
      options[:default]
    end

    # Only relevant for optional params
    def discard_nils?
      !options[:nils]
    end

    def discard_empty?
      options[:discard_empty]
    end

    def discard_invalid?
      self.options[:discard_invalid]
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mutations-0.7.0 lib/mutations/input_filter.rb