module Trop::GemVersion

load File.dirname(__FILE__) + '/../../rakelib/gem_version.rake'

Public Class Methods

check_lib_version_rb() click to toggle source
# File lib/trop/gem_version.rb, line 74
def self.check_lib_version_rb
        content = Pathname.new(self.version_file_rb).read
  version_ok = content.scan(/VERSION.*["']+\d+\.\d+[\.\d+]+["']+/)
  version_ok
end
check_lib_version_rb?() click to toggle source
# File lib/trop/gem_version.rb, line 69
def self.check_lib_version_rb?
  return false if (self.check_lib_version_rb.nil?)
  true
end
commit_and_push(project_directory = nil, msg = nil) { |g| ... } click to toggle source
# File lib/trop/gem_version.rb, line 121
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)
  g.add(self.version_file_rb)
  g.add(self.gemspec_name)
  g.add('VERSION')
  yield(g) if block_given?
  g.commit(msg || @@default_commit_message)
  v = @@version
  system("git tag -f -a -m 'Version v#{v}' v#{v}")
  system("git push > #{DEVNULL} 2>&1")
  system("git push --tags -f > #{DEVNULL} 2>&1")
  g.push
end
gem_version_file=(str) click to toggle source
# File lib/trop/gem_version.rb, line 16
def self.gem_version_file=(str)
  @@gem_version_file = str
end
gemspec_name() click to toggle source
# File lib/trop/version.rb, line 20
def self.gemspec_name
  Trop::VERSION_NAME + '.gemspec'
end
increment_and_push() click to toggle source
# File lib/trop/gem_version.rb, line 44
def self.increment_and_push
  self.update_version(self.increment_version)
  self.rewrite_gemspec
  self.commit_and_push
  self.version
end
increment_version() click to toggle source
# File lib/trop/gem_version.rb, line 51
def self.increment_version
  version = self.next_version
  components = version.split('.')
  components.push((components.pop.to_i + 1).to_s)
  @@version = components.join('.')
  ENV['VERSION'] = @@version
  @@version
end
init_version_file() click to toggle source
# File lib/trop/gem_version.rb, line 38
def self.init_version_file
  file = File.new(@@gem_version_file, 'w')
  file.puts '0.0.1'
  file.close
end
next_version() click to toggle source
# File lib/trop/gem_version.rb, line 20
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
rewrite_gemspec() click to toggle source
# File lib/trop/gem_version.rb, line 60
def self.rewrite_gemspec
  spec_path = FileUtils.getwd + '/' + self.gemspec_name
  spec_gem = Gem::Specification::load(spec_path)
  spec_gem.version = @@version || self.next_version
  spec_gem.files = spec_gem.files + Trop::FileFinder::my_gemspec_fffind([File.expand_path('./lib'),File.expand_path('rakelib')])
  File.open(spec_path, 'w') {|f| f.write spec_gem.to_ruby}
  return spec_gem.version
end
set_version(version) click to toggle source
# File lib/trop/gem_version.rb, line 29
def self.set_version(version)
  raise "Invalid version format" unless self.version_format_valid?(version)
  self.update_version(version)
end
update_lib_version_rb(version) click to toggle source
# File lib/trop/gem_version.rb, line 80
def self.update_lib_version_rb(version)
  unless self.check_lib_version_rb?
    puts "version out of sync"
    assert false
    return
  end
    # update
  content = Pathname.new(self.version_file_rb).read
  File.open(self.version_file_rb + '.tmp', 'w') do |out|
    content.each_line do |l|
      ret = l.match(/VERSION.*["']+\d+\.\d+[\.\d+]+["']+/)
      if ret
        out.print "  VERSION = '" + version + "'\n"
      else
        out.print (l)
      end
    end
  end
  # rename
  FileUtils.cp( self.version_file_rb + '.tmp',self.version_file_rb, preserve: false)
end
update_version(new_version) click to toggle source
# File lib/trop/gem_version.rb, line 102
def self.update_version(new_version)
  # 0. ENV
  @@version = new_version
  ENV['VERSION'] = @@version
  # 1. next_version
  file = File.new(@@gem_version_file, 'w')
  file.print new_version + "\n"
  file.close
  # 2. VERSION
  file = File.new('VERSION', 'w')
  file.print new_version + "\n"
  file.close
  # 3.
  self.update_lib_version_rb(@@version)
  # 4. gemspec
  self.rewrite_gemspec
  ENV['VERSION'] = @@version
end
version() click to toggle source
# File lib/trop/version.rb, line 12
def self.version
  Trop::VERSION
end
version_file_rb() click to toggle source
# File lib/trop/version.rb, line 16
def self.version_file_rb
  File.expand_path('version.rb', __dir__)
end
version_format_valid?(version) click to toggle source
# File lib/trop/gem_version.rb, line 34
def self.version_format_valid?(version)
  (version && version =~ /^\d+\.\d+[\.\d+]+$/)
end
version_name() click to toggle source
# File lib/trop/version.rb, line 8
def self.version_name
  Trop::VERSION_NAME
end