Class: HTTY::CLI::Commands::App

Inherits:
HTTY::CLI::Command
  • Object
show all
Defined in:
lib/htty/rack/commands/app.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.categoryObject

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



5
6
7
# File 'lib/htty/rack/commands/app.rb', line 5

def self.category
  'Rack'
end

.command_line_argumentsObject

Returns the arguments for the command-line usage of the app command.



10
11
12
# File 'lib/htty/rack/commands/app.rb', line 10

def self.command_line_arguments
  'constant'
end

.helpObject

Returns the help text for the app command.



15
16
17
# File 'lib/htty/rack/commands/app.rb', line 15

def self.help
  'Sets the active app'
end

.help_extendedObject

Returns the extended help text for the app command.



20
21
22
23
# File 'lib/htty/rack/commands/app.rb', line 20

def self.help_extended
  'Sets the app to the constant provided. The app must be required first.' +
  'This operation does not clear cookies.'
end

Instance Method Details

#performObject

Performs the app command.



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/htty/rack/commands/app.rb', line 26

def perform
  unless arguments.length == 1
     raise ArgumentError,
           "wrong number of arguments (#{arguments.length} for 1)"
  end
  
  app = Module.const_get(arguments.first)
  
  add_request_if_has_response do |request|
    request.app = app
    request
  end
end