Skip to content

Commit d5e1510

Browse files
committed
Capturing all
1 parent 7ba06f4 commit d5e1510

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

app/models/job.rb

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,15 @@ def run_task
1818
success = true
1919

2020
FileUtils.chdir project.repo.path do
21-
out = capture_stdout do
21+
out = capture(:stderr) do
2222
success = Strano::CLI.parse(Strano::Logger.new(self), full_command.flatten).execute!
2323
end
24-
puts "\n \e[1;32m> #{out.string}\e" unless out.string.blank?
24+
25+
if out.is_a?(String)
26+
puts "\n \e[33m> #{out}\e" unless out.blank?
27+
elsif !out.string.blank?
28+
puts "\n \e[1;32m> #{out.string}\e"
29+
end
2530
end
2631

2732
!!success
@@ -49,13 +54,11 @@ def results
4954
private
5055

5156
def full_command
52-
%W(-f #{Rails.root.join('Capfile.repos')} -f Capfile -Xx#{verbosity}) + mapped_variables + command.split(' ')
57+
%W(-f #{Rails.root.join('Capfile.repos')} -f Capfile -Xx#{verbosity}) + branch_setting + command.split(' ')
5358
end
5459

55-
def mapped_variables
56-
variables.map do |k,v|
57-
%W(-s #{k}=#{v}) unless v.blank?
58-
end
60+
def branch_setting
61+
%W(-s branch=#{branch}) unless branch.blank?
5962
end
6063

6164
def execute_task

lib/kernel.rb

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,19 @@
22

33
module Kernel
44

5-
def capture_stdout
6-
out = StringIO.new
7-
$stdout = out
8-
yield
9-
return out
10-
ensure
11-
$stdout = STDOUT
5+
def capture(stream)
6+
return super if stream.is_a?(String)
7+
8+
begin
9+
stream = stream.to_s
10+
eval "$#{stream} = StringIO.new"
11+
yield
12+
result = eval("$#{stream}").string
13+
ensure
14+
eval("$#{stream} = #{stream.upcase}")
15+
end
16+
17+
result
1218
end
1319

1420
end

0 commit comments

Comments
 (0)