Module: GemVersion

Defined in:
lib/gem_version.rb

Constant Summary collapse

@@gem_version_file =
'next_gem_version'
@@default_commit_message =
'incremented gem version'

Class Method Summary collapse

Class Method Details

.commit_and_push(project_directory = nil, msg = nil) {|g| ... } ⇒ Object

Yields:

  • (g)


60
61
62
63
64
65
66
# File 'lib/gem_version.rb', line 60

def self.commit_and_push(project_directory = nil, msg = nil, &block)
  g=Git.open(project_directory || Dir.pwd, :log=>Logger.new(STDOUT))
  g.add(@@gem_version_file)
  yield(g) if block_given?
  g.commit(msg || @@default_commit_message)
  g.push
end

.gem_version_file=(str) ⇒ Object



12
13
14
# File 'lib/gem_version.rb', line 12

def self.gem_version_file=(str)
  @@gem_version_file = str
end

.increment_and_pushObject



40
41
42
43
# File 'lib/gem_version.rb', line 40

def self.increment_and_push
  self.increment_version
  self.commit_and_push
end

.increment_versionObject



45
46
47
48
49
50
51
52
# File 'lib/gem_version.rb', line 45

def self.increment_version
  version = self.next_version
  components = version.split('.')
  components.push((components.pop.to_i + 1).to_s)
  new_version = components.join('.')
  update_version(new_version)
  version
end

.init_version_fileObject



34
35
36
37
38
# File 'lib/gem_version.rb', line 34

def self.init_version_file
  file = File.new(@@gem_version_file, 'w')
  file.puts '0.0.1'
  file.close
end

.next_versionObject



16
17
18
19
20
21
22
23
# File 'lib/gem_version.rb', line 16

def self.next_version
  init_version_file unless File.exist?(@@gem_version_file)
  file = File.new(@@gem_version_file, 'r')
  version = file.gets.chomp
  raise "#{@@gem_version_file} file corrupt" unless self.version_format_valid?(version)
  file.close
  version
end

.set_version(version) ⇒ Object



25
26
27
28
# File 'lib/gem_version.rb', line 25

def self.set_version(version)
  raise "Invalid version format" unless self.version_format_valid?(version)
  update_version(version)
end

.update_version(new_version) ⇒ Object



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

def self.update_version(new_version)
  file = File.new(@@gem_version_file, 'w')
  file.puts new_version
  file.close    
end

.version_format_valid?(version) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/gem_version.rb', line 30

def self.version_format_valid?(version)
  (version && version =~ /^\d+\.\d+[\.\d+]+$/)
end