131: def prepare
132: require "pathname"
133: @file = Pathname.new(@file)
134: @content = @file.read
135: @match = @content.match(/#{@name}\s*=\s*['"](\d+\.\d+\.\d+)['"]/)
136: @new_version = @match[1].succ
137: @newcont = @content[0..@match.begin(1)-1] + @new_version + @content[@match.end(1)..-1]
138: raise "Can't find version string in #{@file}." if @match.nil?
139: puts "Find version string #{@match[1]} and will change to #{@new_version}"
140:
141:
142: check_version = nil
143: @org = @file.parent + "#{@file.basename}.org"
144: FileUtils.cp @file, @org
145: @file.open("w") do |f|
146: f.print @newcont
147: end
148:
149:
150: IO.popen("ruby", "r+") do |ruby|
151: ruby << "m = Module.new\nm.module_eval(File.read(\"Rakefile\"))\nprint Marshal.dump(m.const_get(:VERS))\n"
152: ruby.close_write
153: check_version = Marshal.load(ruby.read)
154: end
155:
156: FileUtils.mv @org, @file
157: raise "Constant VERS in Rakefile must be same as 3rd argument of ChangeVersion step." unless @new_version == check_version
158:
159: VERS.replace @new_version
160: end