Class Rake::ShipitTask::Step::ChangeVersion
In: lib/shipit.rb
Parent: Object

Methods

new   prepare   run  

Public Class methods

[Source]

     # File lib/shipit.rb, line 126
126:         def initialize(step, file, name="VERSION")
127:                 @file = file
128:                 @name = name
129:         end

Public Instance methods

[Source]

     # File lib/shipit.rb, line 131
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:                 # check content of Rakefile
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:                 ## run ruby not to duplicate rake tasks.
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

[Source]

     # File lib/shipit.rb, line 167
167:         def run
168:                 puts "Changing version to #{@new_version}"
169:                 @file.open("w") do |f|
170:                         f.print @newcont
171:                 end
172:         end

[Validate]