Class: RequestHandler::IncludeOptionParser

Inherits:
OptionParser show all
Defined in:
lib/request_handler/include_option_parser.rb

Instance Method Summary collapse

Methods inherited from OptionParser

#initialize

Constructor Details

This class inherits a constructor from RequestHandler::OptionParser

Instance Method Details

#allowed_options(options) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/request_handler/include_option_parser.rb', line 15

def allowed_options(options)
  options.map do |option|
    option.gsub!(".", ::RequestHandler.configuration.separator)
    begin
      RequestHandler.configuration.validation_engine.validate!(option, allowed_options_type).output.to_sym
    rescue Validation::Error
      raise_error("OPTION_NOT_ALLOWED", "#{option} is not an allowed include option", OptionNotAllowedError)
    end
  end
end

#fetch_optionsObject



26
27
28
29
# File 'lib/request_handler/include_option_parser.rb', line 26

def fetch_options
  raise_error("INVALID_QUERY_PARAMETER", "must not be empty") if empty_param?("include")
  params.fetch("include", "")
end

#runObject



7
8
9
10
11
12
13
# File 'lib/request_handler/include_option_parser.rb', line 7

def run
  return [] unless params.key?("include")

  options = fetch_options
  raise_error("INVALID_QUERY_PARAMETER", "must not contain a space") if options.include?(" ")
  allowed_options(options.split(","))
end