Class: RakeRack::Version

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

Constant Summary collapse

HISTORY_FILE =
"history.rdoc"

Class Method Summary collapse

Class Method Details

.add_history_header(version, history_file = HISTORY_FILE) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/version.rb', line 31

def self.add_history_header(version, history_file = HISTORY_FILE)
  history = current_history history_file
  File.open history_file, "w" do |f|
    f.puts "== #{version} (#{Time.now.strftime "%d %B %Y"})"
    f.puts
    f.print history
  end
  puts "Added version to history.rdoc"
end

.commit(version) ⇒ Object



50
51
52
53
# File 'lib/version.rb', line 50

def self.commit version
  `git add . && git commit -m 'increment version to #{version}'`
  puts "Committed change"
end

.current_history(history_file) ⇒ Object



4
5
6
7
8
9
10
11
# File 'lib/version.rb', line 4

def self.current_history history_file
  unless File.exists? history_file
     File.open history_file, "w" do |f|
       f.puts "== 0.0.0 (#{Time.now.strftime "%d %B %Y"})"
     end
  end
  File.read history_file
end

.gem?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/version.rb', line 60

def self.gem?
  !Dir.glob('*.gemspec').empty?
end

.latest_versionObject



13
14
15
16
17
18
19
20
# File 'lib/version.rb', line 13

def self.latest_version
  latest_version_string = current_history(HISTORY_FILE)[/== ([\d\.]*)/, 1] || "0.0.0"
  @latest_version ||= latest_version_string.split(".").map(&:to_i)
  def @latest_version.to_s
    join "."
  end
  @latest_version
end

.tag(version) ⇒ Object



55
56
57
58
# File 'lib/version.rb', line 55

def self.tag version
  `git tag #{version}`
  puts "Tagged with #{version}"
end

.to_sObject



16
17
18
# File 'lib/version.rb', line 16

def @latest_version.to_s
  join "."
end

.update_gem(version) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/version.rb', line 41

def self.update_gem version
  path = Dir.glob('*.gemspec').first
  text = File.read path
  File.open(path, "w") do |file|
    file.puts text.sub(/(.*version\s*=\s*)(['|"].*['|"])/, "\\1'#{version}'")
  end
  puts "Added version to .gemfile"
end

.update_to(version) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/version.rb', line 22

def self.update_to version
  add_history_header version
  update_gem version if gem?
  commit version
  tag version
  branch = `git symbolic-ref HEAD`[%r{.*/(.*)}, 1]
  puts "To push the new tag, use 'git push origin #{branch} --tags'"
end