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.
-
#skip! ⇒ Object
Skip running this command.
-
#skip? ⇒ Boolean
Boolean indicating whether this command will run.
-
#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.
49 50 51 |
# File 'lib/hub/args.rb', line 49 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’ ]
73 74 75 |
# File 'lib/hub/args.rb', line 73 def flags self - words end |
#skip! ⇒ Object
Skip running this command.
39 40 41 |
# File 'lib/hub/args.rb', line 39 def skip! @skip ||= true end |
#skip? ⇒ Boolean
Boolean indicating whether this command will run.
44 45 46 |
# File 'lib/hub/args.rb', line 44 def skip? @skip end |
#to_exec ⇒ Object
Array of ‘executable` followed by all args suitable as arguments for `exec` or `system` calls.
55 56 57 |
# File 'lib/hub/args.rb', line 55 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’ ]
64 65 66 |
# File 'lib/hub/args.rb', line 64 def words reject { |arg| arg.index('-') == 0 } end |