Class: GemspecVersioner
- Inherits:
-
Object
- Object
- GemspecVersioner
- Defined in:
- lib/rake-extensions.rb
Constant Summary collapse
- VERSION_REGEX =
/^(\s*.*?\.version\s*?=\s*['\"])(.*)(['\"])/i
- DATE_REGEX =
/^(\s*.*?\.date\s*?=\s*['\"])(.*)(['\"])/
Instance Method Summary collapse
- #get_current_version ⇒ Object
- #get_next_version(jump) ⇒ Object
- #increment_version(jump) ⇒ Object
-
#initialize(version_dir) ⇒ GemspecVersioner
constructor
A new instance of GemspecVersioner.
- #update_version(new_version) ⇒ Object
Constructor Details
#initialize(version_dir) ⇒ GemspecVersioner
Returns a new instance of GemspecVersioner.
109 110 111 |
# File 'lib/rake-extensions.rb', line 109 def initialize(version_dir) @version_dir = version_dir end |
Instance Method Details
#get_current_version ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/rake-extensions.rb', line 117 def get_current_version() current_version = nil FileUtils.cd @version_dir, :verbose => false do FileList['*.gemspec'].each do |file| text = File.read(file) if match = text.match(VERSION_REGEX) current_version = match.captures[1] end end end current_version end |
#get_next_version(jump) ⇒ Object
112 113 114 115 116 |
# File 'lib/rake-extensions.rb', line 112 def get_next_version(jump) current_version = get_current_version() v = Version.new(current_version) v.send(jump) end |
#increment_version(jump) ⇒ Object
129 130 131 132 133 |
# File 'lib/rake-extensions.rb', line 129 def increment_version(jump) next_version = get_next_version(jump) puts "increment version from #{get_current_version} ==> #{next_version}" update_version(next_version) end |
#update_version(new_version) ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/rake-extensions.rb', line 134 def update_version(new_version) FileUtils.cd @version_dir, :verbose => false do FileList['*.gemspec'].each do |file| text = File.read(file) today = Time.now.strftime("%Y-%m-%d") correct_date_contents = text.gsub(DATE_REGEX, "\\1#{today}\\3") new_contents = correct_date_contents.gsub(VERSION_REGEX, "\\1#{new_version}\\3") File.open(file, "w") { |f| f.write new_contents } end end end |