Sha256: 25f72f96ba54a83aa099893cf7b86b5c21ed67f8072b542893917017d1046535

Contents?: true

Size: 838 Bytes

Versions: 1

Compression:

Stored size: 838 Bytes

Contents

# frozen_string_literal: true
require 'request_handler/schema_handler'
require 'request_handler/error'
module RequestHandler
  class FilterHandler < SchemaHandler
    def initialize(params:, schema:, additional_url_filter:, schema_options: {})
      super(schema: schema, schema_options: schema_options)
      @filter = params.fetch('filter') { {} }
      raise ExternalArgumentError, filter: 'must be a Hash' unless @filter.is_a?(Hash)
      Array(additional_url_filter).each do |key|
        key = key.to_s
        raise build_error(key) unless @filter[key].nil?
        @filter[key] = params.fetch(key) { nil }
      end
    end

    def run
      validate_schema(filter)
    end

    private

    def build_error(_key)
      InternalArgumentError.new(filter: 'the filter key was set twice')
    end

    attr_reader :filter
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
request_handler-0.8.0 lib/request_handler/filter_handler.rb