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.



84
85
86
87
88
89
90
91
# File 'lib/htty/cli/commands.rb', line 84

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.



94
95
96
97
98
99
100
101
102
103
104
# File 'lib/htty/cli/commands.rb', line 94

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