Module: HTTY::CLI::Commands

Extended by:
Enumerable
Defined in:
lib/htty/cli/commands.rb

Overview

Contains classes that implement commands in the user interface.

Defined Under Namespace

Classes: Address, BodyClear, BodyEdit, BodyRequest, BodyRequestOpen, BodyResponse, BodyResponseOpen, BodySet, BodyUnset, Cd, CookieAdd, CookieRemove, Cookies, CookiesAdd, CookiesClear, CookiesRemove, CookiesRemoveAll, CookiesUse, Delete, Exit, Follow, Form, FormAdd, FormClear, FormRemove, FormRemoveAll, FragmentClear, FragmentSet, FragmentUnset, Get, HeaderSet, HeaderUnset, HeadersClear, HeadersRequest, HeadersResponse, HeadersSet, HeadersUnset, HeadersUnsetAll, Help, History, HistoryVerbose, HostSet, HttpDelete, HttpGet, HttpHead, HttpOptions, HttpPatch, HttpPost, HttpPut, HttpTrace, Patch, PathSet, PortSet, Post, Put, QueryAdd, QueryClear, QueryRemove, QuerySet, QueryUnset, QueryUnsetAll, Quit, Reuse, SchemeSet, SslVerification, SslVerificationOff, SslVerificationOn, Status, Undo, UserinfoClear, UserinfoSet, UserinfoUnset

Class Method Summary collapse

Class Method Details

.build_for(command_line, attributes = {}) ⇒ Object

Returns a HTTY::CLI::Command descendant whose command line representation matches the specified command_line. If an attributes hash is specified, it is used to initialize the command.



14
15
16
17
18
19
20
21
# File 'lib/htty/cli/commands.rb', line 14

def self.build_for(command_line, attributes={})
  each do |klass|
    if (command = klass.build_for(command_line, attributes))
      return command
    end
  end
  nil
end

.eachObject

Yields each HTTY::CLI::Command descendant in turn.



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/htty/cli/commands.rb', line 24

def self.each
  Dir.glob "#{File.dirname __FILE__}/commands/*.rb" do |f|
    class_name = File.basename(f, '.rb').gsub(/^(.)/, &:upcase).
                                         gsub(/_(\S)/) do |initial|
      initial.gsub(/_/, '').upcase
    end
    klass = const_get(class_name) rescue nil
    yield klass if klass
  end
  self
end