Class: Versionr

Inherits:
Object
  • Object
show all
Defined in:
lib/versionr.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version_dir = Dir.pwd) ⇒ Versionr

Returns a new instance of Versionr.



9
10
11
12
13
14
15
16
# File 'lib/versionr.rb', line 9

def initialize(version_dir = Dir.pwd)
  @version_dir = "#{version_dir}" + "/VERSION"
  version = YAML.load_file(@version_dir)
  @major = version['version']['major']
  @minor = version['version']['minor']
  @patch = version['version']['patch']
  rescue abort("Can't open %s" % version_dir)
end

Instance Attribute Details

#majorObject (readonly)

Returns the value of attribute major.



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

def major
  @major
end

#minorObject (readonly)

Returns the value of attribute minor.



6
7
8
# File 'lib/versionr.rb', line 6

def minor
  @minor
end

#patchObject (readonly)

Returns the value of attribute patch.



7
8
9
# File 'lib/versionr.rb', line 7

def patch
  @patch
end

Instance Method Details

#bump_majorObject



28
29
30
31
32
33
# File 'lib/versionr.rb', line 28

def bump_major
  @major += 1
  @minor = 0
  @patch = 0
  write_version
end

#bump_minorObject



35
36
37
38
39
# File 'lib/versionr.rb', line 35

def bump_minor
  @minor += 1
  @patch = 0
  write_version
end

#bump_patchObject



41
42
43
44
# File 'lib/versionr.rb', line 41

def bump_patch
  @patch += 1
  write_version
end

#full_versionObject



23
24
25
26
# File 'lib/versionr.rb', line 23

def full_version
  version =  "#{@major}.#{@minor}.#{@patch}"
  return version
end

#write_versionObject



18
19
20
21
# File 'lib/versionr.rb', line 18

def write_version
  data = {"version" => { "major" => @major, "minor" => @minor, "patch" => @patch } }
  File.open(@version_dir, 'w+') { |f| f.write(data.to_yaml) }
end