Module: MSPRelease::Project::Ruby
- Defined in:
- lib/msp_release/project/ruby.rb
Overview
This kind of project uses a ruby file with a VERSION constant to be the authorative source for the version
Instance Attribute Summary collapse
-
#ruby_version_file ⇒ Object
readonly
Returns the value of attribute ruby_version_file.
Instance Method Summary collapse
Instance Attribute Details
#ruby_version_file ⇒ Object (readonly)
Returns the value of attribute ruby_version_file.
7 8 9 |
# File 'lib/msp_release/project/ruby.rb', line 7 def ruby_version_file @ruby_version_file end |
Instance Method Details
#version ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/msp_release/project/ruby.rb', line 30 def version Dir.chdir(@dir) do File.open(ruby_version_file, 'r') do |f| v_line = f.readlines.map {|l|version_pattern.match(l)}.compact.first raise "Couldn't parse version from #{ruby_version_file}" unless v_line MSPRelease::Version.new(* (2..4).map {|i|v_line[i]} ) end end end |
#version_pattern ⇒ Object
9 10 11 |
# File 'lib/msp_release/project/ruby.rb', line 9 def version_pattern /VERSION *= *(['"])([0-9]+)\.([0-9]+)\.([0-9]+)\1/ end |
#write_version(new_version) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/msp_release/project/ruby.rb', line 13 def write_version(new_version) lines = File.open(ruby_version_file, 'r') { |f| f.readlines } lines = lines.map do |line| if match = version_pattern.match(line) line.gsub(/( *VERSION *= *)(['"]).+\2$/, "\\1\\2#{new_version.to_s}\\2") else line end end File.open(ruby_version_file, 'w') { |f| f.write(lines) } defined?(super) ? Array(super).push(ruby_version_file) : [ruby_version_file] end |