Class: Rake::Delphi::EchoToFile

Inherits:
BasicTask show all
Defined in:
lib/rake/common/echotask.rb

Instance Method Summary collapse

Methods inherited from BasicTask

#trace?

Constructor Details

#initialize(task, ifile, ofile, vars) ⇒ EchoToFile

Returns a new instance of EchoToFile.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rake/common/echotask.rb', line 10

def initialize(task, ifile, ofile, vars)
    super(task)
    @task.out "#{ifile} -> #{ofile}"
    FileUtils.mkdir_p(File.dirname(ofile))
    File.open(ifile, 'r') do |f|
        File.open(ofile, 'w') do |w|
            while (line = f.gets)
                # replace ${var1.var2.var3} with its value from xml
                line.gsub!(/\$\{(.+?)\}/) do |match|
                    val = nil
                    $1.split(".").each do |part|
                        val = val.nil? ? vars[part] : val[part]
                    end
                    match = val.nil? ? match : val
                end if vars
                w.puts line
            end
            w.close
        end
        f.close
    end
end