Module: Trebor::Command
- Included in:
- RemoteCommand, Task
- Defined in:
- lib/trebor/command.rb
Instance Method Summary collapse
- #as(name, &block) ⇒ Object
- #call(*names) ⇒ Object
- #on(host, user, options, &block) ⇒ Object
- #run(command) ⇒ Object
- #test?(name, option) ⇒ Boolean
- #with(environment, &block) ⇒ Object
- #within(directory, &block) ⇒ Object
Instance Method Details
#as(name, &block) ⇒ Object
21 22 23 |
# File 'lib/trebor/command.rb', line 21 def as(name, &block) # pending end |
#call(*names) ⇒ Object
45 46 47 |
# File 'lib/trebor/command.rb', line 45 def call(*names) toplevel.call(*names) end |
#on(host, user, options, &block) ⇒ Object
5 6 7 |
# File 'lib/trebor/command.rb', line 5 def on(host, user, , &block) On.new(self, host, user, ).action block end |
#run(command) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/trebor/command.rb', line 25 def run(command) Open3.popen3(fetch(command)) do |inn, out, err, wait| inn.close = out.read.chomp error = err.read.chomp Trebor.logger.info if !.empty? Trebor.logger.error error if !error.empty? (wait ? wait.value : $?).exitstatus end end |
#test?(name, option) ⇒ Boolean
39 40 41 42 43 |
# File 'lib/trebor/command.rb', line 39 def test?(name, option) command = %([ #{option} #{name} ]) run(command) == 0 end |
#with(environment, &block) ⇒ Object
17 18 19 |
# File 'lib/trebor/command.rb', line 17 def with(environment, &block) With.new(self, environment).action block end |
#within(directory, &block) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/trebor/command.rb', line 9 def within(directory, &block) joined_directory = File.join(*[current_directory, directory].compact) = "Directory does not exist '#{joined_directory}'" raise unless test?(joined_directory, '-d') Within.new(self, directory).action block end |