Class: Versionator::Version

Inherits:
Object
  • Object
show all
Includes:
File, Git
Defined in:
lib/versionator/version.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Git

#git_checkout, #git_command, #git_commit, #git_current_branch, #git_pull, #git_push, #git_tag

Methods included from File

#read, #write

Constructor Details

#initializeVersion

Returns a new instance of Version.



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/versionator/version.rb', line 7

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

Instance Attribute Details

#majorObject

Returns the value of attribute major.



5
6
7
# File 'lib/versionator/version.rb', line 5

def major
  @major
end

#minorObject

Returns the value of attribute minor.



5
6
7
# File 'lib/versionator/version.rb', line 5

def minor
  @minor
end

#patchObject

Returns the value of attribute patch.



5
6
7
# File 'lib/versionator/version.rb', line 5

def patch
  @patch
end

Instance Method Details

#bump(category) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/versionator/version.rb', line 24

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

#confirm_branch(branch) ⇒ Object



56
57
58
59
60
# File 'lib/versionator/version.rb', line 56

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

#git_releaseObject



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/versionator/version.rb', line 42

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

#release(category) ⇒ Object



62
63
64
65
66
# File 'lib/versionator/version.rb', line 62

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

#version_categories(version_str) ⇒ Object



20
21
22
# File 'lib/versionator/version.rb', line 20

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

#version_nameObject



38
39
40
# File 'lib/versionator/version.rb', line 38

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