Module: Chimps::Utils::ExplicitPath

Included in:
Commands::Delete, Commands::Get, Commands::Post, Commands::Put
Defined in:
lib/chimps-cli/utils/explicit_path.rb

Instance Method Summary collapse

Instance Method Details

#pathObject



21
22
23
24
# File 'lib/chimps-cli/utils/explicit_path.rb', line 21

def path
  p = raw_path.split('?').first
  p =~ /\.(\w+)$/i ? p : "#{p}.#{response_fmt}"
end

#query_paramsObject



11
12
13
14
15
16
17
18
19
# File 'lib/chimps-cli/utils/explicit_path.rb', line 11

def query_params
  return {} unless raw_path.include?('?')
  {}.tap do |h|
    raw_path.split('?')[1].split('&').each do |pair|
      name, value = pair.split('=').map { |string| CGI::unescape(string) }
      h[name] = value
    end
  end
end

#raw_pathObject

Raises:



6
7
8
9
# File 'lib/chimps-cli/utils/explicit_path.rb', line 6

def raw_path
  raise CLIError.new(self.class::USAGE) unless config.argv.size > 1
  config.argv[1]
end