Sha256: 298492a5a2370e0e69bbd409aa7295183e325da3782e78b10afec877b4215862

Contents?: true

Size: 1.62 KB

Versions: 1

Compression:

Stored size: 1.62 KB

Contents

module Versionator
  class Version
    include Versionator::File
    include Versionator::Git
    attr_accessor :major, :minor, :patch

    def initialize
      version_file_content = read rescue nil
      if version_file_content.nil?
        write
        version_file_content = read
        puts "Versionator file created: #{Versionator.version_file}"
      end
      categories = version_categories(version_file_content)
      @major = categories[0]
      @minor = categories[1]
      @patch = categories[2]
    end

    def version_categories(version_str)
      version_str.split(".").collect{|s|s.to_i}
    end

    def bump(category)
      case category
      when :major
        @major += 1
        @minor = 0
        @patch = 0
      when :minor
        @minor += 1
        @patch = 0
      when :patch
        @patch += 1
      end
    end

    def version_name
      [@major,@minor,@patch].join(".")
    end

    def git_release
      current_branch = git_current_branch
      if current_branch == 'master' || confirm_branch(current_branch)
        output = git_checkout(current_branch)
        output += git_pull(current_branch)
        output += git_tag
        output += git_commit
        output += git_push(current_branch)
      else
        output = "Aborting tag. Check out the correct branch and try again."
      end
      output
    end

    def confirm_branch(branch)
      print "Tagging new version on current branch [#{branch}]. Continue? [y]: "
      response = $stdin.gets
      (response =~ /y/i || response == "\n")
    end

    def release(category)
      bump(category)
      write(version_name)
      git_release
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
versionator-0.1.0 lib/versionator/version.rb