Sha256: b5489d4dd4ec4e915b669c3046fe1c3c14c7096d06612ef50857015bb40fb052

Contents?: true

Size: 835 Bytes

Versions: 4

Compression:

Stored size: 835 Bytes

Contents

# frozen_string_literal: true
require 'request_handler/schema_parser'
require 'request_handler/error'
module RequestHandler
  class FilterParser < SchemaParser
    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

4 entries across 4 versions & 1 rubygems

Version Path
request_handler-0.11.0 lib/request_handler/filter_parser.rb
request_handler-0.10.0 lib/request_handler/filter_parser.rb
request_handler-0.9.1 lib/request_handler/filter_parser.rb
request_handler-0.9.0 lib/request_handler/filter_parser.rb