Sha256: 0ba6cf4c8c89b71c44ed39a1e08abf582bc8e18aadc9cc024a8a2fcba5456428

Contents?: true

Size: 939 Bytes

Versions: 2

Compression:

Stored size: 939 Bytes

Contents

# frozen_string_literal: true
require 'request_handler/option_parser'
require 'request_handler/error'
module RequestHandler
  class IncludeOptionParser < OptionParser
    def run
      return [] unless params.key?('include')
      options = fetch_options
      raise ExternalArgumentError, include: 'must not contain a space' if options.include? ' '
      allowed_options(options.split(','))
    end

    def allowed_options(options)
      options.map do |option|
        option.gsub!('.', ::RequestHandler.separator)
        begin
          allowed_options_type.call(option).to_sym
        rescue Dry::Types::ConstraintError
          raise OptionNotAllowedError, option.to_sym => 'is not an allowed include option'
        end
      end
    end

    def fetch_options
      raise ExternalArgumentError, include_options: 'query paramter must not be empty' if empty_param?('include')
      params.fetch('include') { '' }
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
request_handler-0.11.0 lib/request_handler/include_option_parser.rb
request_handler-0.10.0 lib/request_handler/include_option_parser.rb