Module: UberDoc::Util

Defined in:
lib/uberdoc/utils.rb

Class Method Summary collapse

Class Method Details

.execute_command(command, verbose) ⇒ Object

Exectues the given command and optionally dumps the command and its output



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/uberdoc/utils.rb', line 16

def self.execute_command(command, verbose)

    if verbose
        puts ">>>>>>>>>>>>>>>>>>>>>>>>>".green
        puts "Command '#{command}'".green
    end

    res = ""
    Open3.popen3(command) do |stdin, stdout, stderr, thread|

        {:out => stdout, :err => stderr}.each do |key, stream|
            Thread.new do
                until (line = stream.gets).nil? do
                    if key == :out
                        res += line
                    end

                    if verbose
                        case key
                        when :out
                            puts line
                        when :err
                            puts line.red                                    
                        end
                    end
                end
            end
        end

        thread.join
    end
    
    if verbose
        puts "<<<<<<<<<<<<<<<<<<<<<<<<<".green
    end

    return res
end

.template_file_path(file) ⇒ Object



9
10
11
# File 'lib/uberdoc/utils.rb', line 9

def self.template_file_path(file)
    File.absolute_path("#{File.dirname(File.dirname(File.dirname(__FILE__)))}/templates/#{file}") 
end