Class: Console::Mux::Command
- Includes:
- Util
- Defined in:
- lib/console/mux/command.rb
Instance Attribute Summary collapse
-
#commandline ⇒ Object
readonly
Returns the value of attribute commandline.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#[]=(key, value) ⇒ Object
Set an option on this command.
- #dir ⇒ Object
-
#initialize(opts) ⇒ Command
constructor
run (debugging convenience).
- #to_s ⇒ Object
Methods included from Util
#auto_name, #basename, #chop_file_extension, #first_word
Constructor Details
#initialize(opts) ⇒ Command
run (debugging convenience)
missing, a name will be auto-generated from the command
applied to the command in reverse order. A string filter is simply prepended to the command. A symbol is called as a method on RunWith that accepts ‘(command, opts)` args and returns `[new_command, new_opts]`.
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/console/mux/command.rb', line 75 def initialize(opts) @opts = opts.dup # one-level-deep dup, required to properly dup :env, possibly others opts.each do |k,v| @opts[k] = v.dup if v.kind_of?(Hash) end self.env ||= {} self.run_with ||= [] # name need not be unique here. When added to a CommandSet, # within that set it may be assigned a unique name based off # this name. self.name ||= auto_name(command) @commandline = end |
Instance Attribute Details
#commandline ⇒ Object (readonly)
Returns the value of attribute commandline.
54 55 56 |
# File 'lib/console/mux/command.rb', line 54 def commandline @commandline end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
54 55 56 |
# File 'lib/console/mux/command.rb', line 54 def opts @opts end |
Class Method Details
.option_accessor(*syms) ⇒ Object
48 49 50 51 |
# File 'lib/console/mux/command.rb', line 48 def option_accessor(*syms) option_reader(*syms) option_writer(*syms) end |
.option_reader(*syms) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/console/mux/command.rb', line 32 def option_reader(*syms) syms.each do |sym| define_method(sym) do self[sym] end end end |
.option_writer(*syms) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/console/mux/command.rb', line 40 def option_writer(*syms) syms.each do |sym| define_method("#{sym}=") do |val| self[sym] = val end end end |
Instance Method Details
#[](key) ⇒ Object
93 94 95 96 97 98 99 100 |
# File 'lib/console/mux/command.rb', line 93 def [](key) value = opts[key] if value.respond_to? :call value.call(self) else value end end |
#[]=(key, value) ⇒ Object
Set an option on this command. The value
may be a Proc object taking a single argument (or anything that responds to :call
), in which case the value on get (+#[]) will be the result of that Proc called with self
.
106 107 108 |
# File 'lib/console/mux/command.rb', line 106 def []=(key, value) opts[key] = value end |
#dir ⇒ Object
110 111 112 113 114 115 116 117 |
# File 'lib/console/mux/command.rb', line 110 def dir dir = self[:chdir] || '.' if self[:base_dir] && !Pathname.new(dir).absolute? File.join(self[:base_dir], dir) else dir end end |
#to_s ⇒ Object
119 120 121 |
# File 'lib/console/mux/command.rb', line 119 def to_s commandline.sub(/^#{::Console::Mux::BUNDLE_EXEC_SH}/, '*bundle_exec.sh') end |