Class: Bundler::GemVersionTasks
- Inherits:
-
Object
- Object
- Bundler::GemVersionTasks
- Includes:
- Rake::DSL
- Defined in:
- lib/bundler/gem_version_tasks.rb,
lib/bundler/gem_version_tasks/version.rb
Constant Summary collapse
- VERSION =
'0.2.1'
Instance Attribute Summary collapse
-
#gemspec ⇒ Object
readonly
Returns the value of attribute gemspec.
Class Method Summary collapse
Instance Method Summary collapse
- #bump(what) ⇒ Object
- #commit_version(version_file, message) ⇒ Object
-
#initialize(opts = {}) ⇒ GemVersionTasks
constructor
A new instance of GemVersionTasks.
- #install ⇒ Object
- #replace_version(version_file, version) ⇒ Object
- #version ⇒ Object
- #version_file ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ GemVersionTasks
Returns a new instance of GemVersionTasks.
8 9 10 11 |
# File 'lib/bundler/gem_version_tasks.rb', line 8 def initialize( opts={} ) @gemspec = opts.fetch(:gemspec) { Bundler::GemHelper.gemspec } @git_command = opts.fetch(:git_command, 'git') end |
Instance Attribute Details
#gemspec ⇒ Object (readonly)
Returns the value of attribute gemspec.
6 7 8 |
# File 'lib/bundler/gem_version_tasks.rb', line 6 def gemspec @gemspec end |
Class Method Details
.install! ⇒ Object
49 50 51 |
# File 'lib/bundler/gem_version_tasks.rb', line 49 def self.install! new.install end |
Instance Method Details
#bump(what) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/bundler/gem_version_tasks.rb', line 13 def bump(what) major,minor,patch = version.segments case what when :major major += 1 minor = 0 patch = 0 when :minor minor = minor.next patch = 0 when :patch patch = patch.next else raise 'need to specify what to bump in :major, :minor, :patch' end "#{major}.#{minor}.#{patch}" end |
#commit_version(version_file, message) ⇒ Object
37 38 39 |
# File 'lib/bundler/gem_version_tasks.rb', line 37 def commit_version(version_file, ) `#{@git_command} commit -m "#{}" #{version_file}` end |
#install ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/bundler/gem_version_tasks.rb', line 54 def install desc "print current version" task 'version' do puts version end namespace 'version' do desc "write a specific version - example: rake version:write VERSION=1.2.3" task 'write' do new_version = ENV['VERSION'] replace_version(version_file, new_version) end end namespace 'version:bump' do desc "Bump the major version by 1" task 'major' do new_version = bump(:major) replace_version(version_file, new_version) puts new_version end desc "Bump the minor version by 1" task 'minor' do new_version = bump(:minor) replace_version(version_file, new_version) puts new_version end desc "Bump the patch version by 1" task 'patch' do new_version = bump(:patch) replace_version(version_file, new_version) puts new_version end end end |
#replace_version(version_file, version) ⇒ Object
31 32 33 34 35 |
# File 'lib/bundler/gem_version_tasks.rb', line 31 def replace_version(version_file, version) lines = File.readlines(version_file).map { |l| l.gsub(/\s*VERSION\s*=.*/,"VERSION='#{version}'") } File.open(version_file,'w') {|f| f.write(lines.join('')) } commit_version(version_file, "Bumping to version #{version}") end |
#version ⇒ Object
45 46 47 |
# File 'lib/bundler/gem_version_tasks.rb', line 45 def version gemspec.version end |
#version_file ⇒ Object
41 42 43 |
# File 'lib/bundler/gem_version_tasks.rb', line 41 def version_file gemspec.files.grep(/\/version.rb$/).first end |