Class: FlavorGem::BumpTasks

Inherits:
Object
  • Object
show all
Includes:
Rake::DSL
Defined in:
lib/flavor_gem/bump.rb

Overview

bump task implementation, needs refactoring

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version_file = Dir["lib/**/version.rb"][0]) ⇒ BumpTasks

Returns a new instance of BumpTasks.



48
49
50
51
52
53
# File 'lib/flavor_gem/bump.rb', line 48

def initialize(version_file = Dir["lib/**/version.rb"][0])
  @version_file = version_file
  @version_data = File.read @version_file
  version = /\d+\.\d+\.\d+/.match @version_data
  @major, @minor, @patch = extract_current_version version[0]
end

Instance Attribute Details

#version_fileObject (readonly)

Returns the value of attribute version_file.



40
41
42
# File 'lib/flavor_gem/bump.rb', line 40

def version_file
  @version_file
end

Class Method Details

.install_tasks(version_file) ⇒ Object



43
44
45
# File 'lib/flavor_gem/bump.rb', line 43

def install_tasks(version_file)
  new(version_file).install
end

Instance Method Details

#bump(d_major = 0, d_minor = 0, d_patch = 1) ⇒ Object



63
64
65
66
67
68
69
70
71
# File 'lib/flavor_gem/bump.rb', line 63

def bump(d_major = 0, d_minor = 0, d_patch = 1)
  major = @major + d_major
  minor = @minor + d_minor
  patch = @patch + d_patch
  major = 0 if major < 0
  minor = 0 if minor < 0 || d_major > 0
  patch = 0 if patch < 0 || d_major > 0 || d_minor > 0
  [major, minor, patch].join "."
end

#extract_current_version(version) ⇒ Object



55
56
57
# File 'lib/flavor_gem/bump.rb', line 55

def extract_current_version(version)
  version.split(".").map(&:to_i)
end

#installObject



81
82
83
84
85
# File 'lib/flavor_gem/bump.rb', line 81

def install
  install_version_task
  install_all_bump_task
  install_default_bump_task
end

#old_versionObject



59
60
61
# File 'lib/flavor_gem/bump.rb', line 59

def old_version
  [@major, @minor, @patch].join "."
end

#save_version_file(new_version) ⇒ Object



73
74
75
76
77
78
79
# File 'lib/flavor_gem/bump.rb', line 73

def save_version_file(new_version)
  version_regex = /\d+\.\d+\.\d+/
  new_version_data = @version_data.gsub version_regex, new_version
  File.open(@version_file, "w") do |f|
    f.write new_version_data
  end
end