Class: Hub::Args
- Inherits:
-
Array
- Object
- Array
- Hub::Args
- Defined in:
- lib/hub/args.rb
Overview
The Args class exists to make it more convenient to work with command line arguments intended for git from within the Hub codebase.
The ARGV array is converted into an Args instance by the Hub instance when instantiated.
Instance Attribute Summary collapse
-
#executable ⇒ Object
Returns the value of attribute executable.
Instance Method Summary collapse
-
#after(command = nil, &block) ⇒ Object
With no arguments, returns the ‘after` callback.
-
#after? ⇒ Boolean
Boolean indicating whether an ‘after` callback has been set.
-
#flags ⇒ Object
All the flags (as opposed to words) contained in this argument list.
-
#initialize(*args) ⇒ Args
constructor
A new instance of Args.
-
#to_exec ⇒ Object
Array of ‘executable` followed by all args suitable as arguments for `exec` or `system` calls.
-
#words ⇒ Object
All the words (as opposed to flags) contained in this argument list.
Constructor Details
#initialize(*args) ⇒ Args
Returns a new instance of Args.
11 12 13 14 15 |
# File 'lib/hub/args.rb', line 11 def initialize(*args) super @executable = ENV["GIT"] || "git" @after = nil end |
Instance Attribute Details
#executable ⇒ Object
Returns the value of attribute executable.
9 10 11 |
# File 'lib/hub/args.rb', line 9 def executable @executable end |
Instance Method Details
#after(command = nil, &block) ⇒ Object
With no arguments, returns the ‘after` callback.
With a single argument, sets the ‘after` callback. Can be set to a string or a proc.
If proc:
The proc is executed after the git command is executed. For
example, the `hub version` command sets the following proc to
print its information after running `git version`:
after { puts "hub version #{version_number}" }
If string:
The string is assumed to be a command and executed after the
git command is executed:
after "echo 'hub version #{version_number}'"
34 35 36 |
# File 'lib/hub/args.rb', line 34 def after(command = nil, &block) @after ||= block ? block : command end |
#after? ⇒ Boolean
Boolean indicating whether an ‘after` callback has been set.
39 40 41 |
# File 'lib/hub/args.rb', line 39 def after? !!@after end |
#flags ⇒ Object
All the flags (as opposed to words) contained in this argument list.
args = Args.new([ ‘remote’, ‘add’, ‘-f’, ‘tekkub’ ]) args.flags == [ ‘-f’ ]
63 64 65 |
# File 'lib/hub/args.rb', line 63 def flags self - words end |
#to_exec ⇒ Object
Array of ‘executable` followed by all args suitable as arguments for `exec` or `system` calls.
45 46 47 |
# File 'lib/hub/args.rb', line 45 def to_exec [executable].concat self end |
#words ⇒ Object
All the words (as opposed to flags) contained in this argument list.
args = Args.new([ ‘remote’, ‘add’, ‘-f’, ‘tekkub’ ]) args.words == [ ‘remote’, ‘add’, ‘tekkub’ ]
54 55 56 |
# File 'lib/hub/args.rb', line 54 def words reject { |arg| arg =~ /^-/ } end |