Class: HTTY::CLI::Commands::Cookies

Inherits:
HTTY::CLI::Command show all
Includes:
Display
Defined in:
lib/htty/cli/commands/cookies.rb

Overview

Encapsulates the cookies command.

Constant Summary

Constant Summary

Constants included from Display

Display::FORMATS

Instance Attribute Summary

Attributes inherited from HTTY::CLI::Command

#arguments, #session

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Display

#break, #format, #formatted_prompt_for, #indent, #logotype, #normal, #notice, #pluralize, #rescuing_from, #say, #say_goodbye, #say_header, #say_hello, #show_headers, #show_request, #show_response, #strong, #word_wrap, #word_wrap_indented

Methods inherited from HTTY::CLI::Command

#add_request_if_new, alias_for, aliases, build_for, command_line, command_line_arguments, complete_for?, #initialize, notify_if_cookies_cleared, raw_name, sanitize_arguments

Constructor Details

This class inherits a constructor from HTTY::CLI::Command

Class Method Details

.categoryObject

Returns the name of a category under which help for the cookies command should appear.



24
25
26
# File 'lib/htty/cli/commands/cookies.rb', line 24

def self.category
  'Building Requests'
end

.helpObject

Returns the help text for the cookies command.



29
30
31
# File 'lib/htty/cli/commands/cookies.rb', line 29

def self.help
  'Displays the cookies of the request'
end

.help_extendedObject

Returns the extended help text for the cookies command.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/htty/cli/commands/cookies.rb', line 34

def self.help_extended
  'Displays the cookies used for the request. Does not communicate with '   +
  "the host.\n"                                                             +
  "\n"                                                                      +
  "This command displays cookies extracted from the request's "             +
  "'#{HTTY::Request::COOKIES_HEADER_NAME}' header, which is nevertheless "  +
  'shown when you type '                                                    +
  "#{strong HTTY::CLI::Commands::HeadersRequest.command_line}.\n"           +
  "\n"                                                                      +
  'Cookies are not required to have unique names. You can add multiple '    +
  'cookies with the same name, and they will be removed in '                +
  "last-in-first-out order.\n"                                              +
  "\n"                                                                      +
  'Cookies are cleared automatically when you change hosts.'
end

.see_also_commandsObject

Returns related command classes for the cookies command.



51
52
53
54
55
56
57
58
# File 'lib/htty/cli/commands/cookies.rb', line 51

def self.see_also_commands
  [HTTY::CLI::Commands::CookiesAdd,
   HTTY::CLI::Commands::CookiesRemove,
   HTTY::CLI::Commands::CookiesRemoveAll,
   HTTY::CLI::Commands::CookiesUse,
   HTTY::CLI::Commands::HeadersRequest,
   HTTY::CLI::Commands::HeadersResponse]
end

Instance Method Details

#performObject

Performs the cookies command.



61
62
63
64
65
66
67
68
69
70
# File 'lib/htty/cli/commands/cookies.rb', line 61

def perform
  cookies = session.requests.last.cookies
  margin = cookies.inject 0 do |result, cookie|
    [cookie.first.length, result].max
  end
  cookies.each do |name, value|
    puts "#{name.rjust margin}: #{value}"
  end
  self
end