Sha256: e854a6d896a237bc0c41cac9ec3e4d9aedc2d87c423a2f8bbe119a5d6cf2ee0c

Contents?: true

Size: 1.69 KB

Versions: 44

Compression:

Stored size: 1.69 KB

Contents

class Version
  attr_accessor :major, :minor, :patch, :build

  def initialize(version_string)
    raise "Invalid version #{version_string}" unless version_string =~ /^(\d+)\.(\d+)\.(\d+)(?:\.(.*?))?$/
    @major = $1.to_i
    @minor = $2.to_i
    @patch = $3.to_i
    @build = $4
  end

  def bump_major(x)
    @major += x.to_i
    @minor = 0
    @patch = 0
    @build = nil
  end

  def bump_minor(x)
    @minor += x.to_i
    @patch = 0
    @build = nil
  end

  def bump_patch(x)
    @patch += x.to_i
    @build = nil
  end

  def update(major, minor, patch, build=nil)
    @major = major
    @minor = minor
    @patch = patch
    @build = build
  end

  def write(desc = nil)
    CLASS_NAME::VERSION_FILE.open('w') { |file| file.puts to_s }
    (BASE_PATH + 'HISTORY').open('a') do |file|
      file.puts "\n== #{to_s} / #{Time.now.strftime '%Y-%m-%d'}\n"
      file.puts "\n* #{desc}\n" if desc
    end
  end

  def to_s
    [major, minor, patch, build].compact.join('.')
  end
end

desc 'Set version: [x.y.z] - explicitly, [1/10/100] - bump major/minor/patch, [.build] - build'
task :version, [:command, :desc] do |t, args|
  version = Version.new(CLASS_NAME::VERSION)
  case args.command
    when /^(\d+)\.(\d+)\.(\d+)(?:\.(.*?))?$/ # Set version explicitly
      version.update($1, $2, $3, $4)
    when /^\.(.*?)$/ # Set build
      version.build = $1
    when /^(\d{1})$/ # Bump patch
      version.bump_patch $1
    when /^(\d{1})0$/ # Bump minor
      version.bump_minor $1
    when /^(\d{1})00$/ # Bump major
      version.bump_major $1
    else # Unknown command, just display VERSION
      puts "#{NAME} #{version}"
      next
  end

  puts "Writing version #{version} to VERSION file"
  version.write args.desc
end

Version data entries

44 entries across 44 versions & 3 rubygems

Version Path
ib-ruby-0.9.2 tasks/version.rake
ib-ruby-0.9.1 tasks/version.rake
ib-ruby-0.9.0 tasks/version.rake
ib-ruby-0.8.5 tasks/version.rake
ib-ruby-0.8.4 tasks/version.rake
ib-ruby-0.8.3 tasks/version.rake
ib-ruby-0.8.1 tasks/version.rake
ib-ruby-0.8.0 tasks/version.rake
ib-ruby-0.7.12 tasks/version.rake
ib-ruby-0.7.11 tasks/version.rake
ib-ruby-0.7.10 tasks/version.rake
ib-ruby-0.7.9 tasks/version.rake
ib-ruby-0.7.8 tasks/version.rake
ib-ruby-0.7.6 tasks/version.rake
ib-ruby-0.7.4 tasks/version.rake
ib-ruby-0.7.3 tasks/version.rake
ib-ruby-0.7.2 tasks/version.rake
ib-ruby-0.7.0 tasks/version.rake
ib-ruby-0.6.1 tasks/version.rake
ib-ruby-0.5.21 tasks/version.rake