class OptParseValidator::OptHeaders

Implementation of the Headers Option

Public Instance Methods

append_help_messages() click to toggle source

@return [ Void ]

# File lib/opt_parse_validator/opts/headers.rb, line 7
def append_help_messages
  super

  option << "Separator to use between the headers: '; '"
  option << "Examples: 'X-Forwarded-For: 127.0.0.1', 'X-Forwarded-For: 127.0.0.1; Another: aaa'"
end
validate(value) click to toggle source

@param [ String ] value

@return [ Hash ] The parsed headers in a hash, with { ‘key’ => ‘value’ } format

Calls superclass method OptParseValidator::OptBase#validate
# File lib/opt_parse_validator/opts/headers.rb, line 17
def validate(value)
  values = super(value).chomp(';').split('; ')

  headers = {}

  values.each do |header|
    raise Error, "Malformed header: '#{header}'" unless header.index(':')

    val = header.split(':', 2)

    headers[val[0].strip] = val[1].strip
  end

  headers
end