Class: Rake::ShipitTask::Step::ChangeVersion

Inherits:
Object
  • Object
show all
Defined in:
lib/shipit.rb

Instance Method Summary collapse

Constructor Details

#initialize(step, file, name = "VERSION") ⇒ ChangeVersion

Returns a new instance of ChangeVersion.



126
127
128
129
# File 'lib/shipit.rb', line 126

def initialize(step, file, name="VERSION")
	@file = file
	@name = name
end

Instance Method Details

#prepareObject



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/shipit.rb', line 131

def prepare
	require "pathname"
	@file     = Pathname.new(@file)
	@content  = @file.read
	@match    = @content.match(/#{@name}\s*=\s*['"](\d+\.\d+\.\d+)['"]/)
	@new_version = @match[1].succ
	@newcont  = @content[0..@match.begin(1)-1] + @new_version + @content[@match.end(1)..-1]
	raise "Can't find version string in #{@file}." if @match.nil?
	puts "Find version string #{@match[1]} and will change to #{@new_version}"

	# check content of Rakefile
	check_version = nil
	@org = @file.parent + "#{@file.basename}.org"
	FileUtils.cp @file, @org
	@file.open("w") do |f|
		f.print @newcont
	end

	## run ruby not to duplicate rake tasks.
	IO.popen("ruby", "r+") do |ruby|
		ruby << <<-EOS
			m = Module.new
			m.module_eval(File.read("Rakefile"))
			print Marshal.dump(m.const_get(:VERS))
		EOS
		ruby.close_write
		check_version = Marshal.load(ruby.read)
	end

	FileUtils.mv @org, @file
	raise "Constant VERS in Rakefile must be same as 3rd argument of ChangeVersion step." unless @new_version == check_version

	VERS.replace @new_version
end

#runObject



166
167
168
169
170
171
# File 'lib/shipit.rb', line 166

def run
	puts "Changing version to #{@new_version}"
	@file.open("w") do |f|
		f.print @newcont
	end
end