Class: Versionr
- Inherits:
-
Object
- Object
- Versionr
- Defined in:
- lib/versionr.rb
Instance Attribute Summary collapse
-
#major ⇒ Object
readonly
Returns the value of attribute major.
-
#minor ⇒ Object
readonly
Returns the value of attribute minor.
-
#patch ⇒ Object
readonly
Returns the value of attribute patch.
Instance Method Summary collapse
- #bump_major ⇒ Object
- #bump_minor ⇒ Object
- #bump_patch ⇒ Object
- #full_version ⇒ Object
-
#initialize(version_dir = Dir.pwd) ⇒ Versionr
constructor
A new instance of Versionr.
- #write_version ⇒ Object
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
#major ⇒ Object (readonly)
Returns the value of attribute major.
5 6 7 |
# File 'lib/versionr.rb', line 5 def major @major end |
#minor ⇒ Object (readonly)
Returns the value of attribute minor.
6 7 8 |
# File 'lib/versionr.rb', line 6 def minor @minor end |
#patch ⇒ Object (readonly)
Returns the value of attribute patch.
7 8 9 |
# File 'lib/versionr.rb', line 7 def patch @patch end |
Instance Method Details
#bump_major ⇒ Object
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_minor ⇒ Object
35 36 37 38 39 |
# File 'lib/versionr.rb', line 35 def bump_minor @minor += 1 @patch = 0 write_version end |
#bump_patch ⇒ Object
41 42 43 44 |
# File 'lib/versionr.rb', line 41 def bump_patch @patch += 1 write_version end |
#full_version ⇒ Object
23 24 25 26 |
# File 'lib/versionr.rb', line 23 def full_version version = "#{@major}.#{@minor}.#{@patch}" return version end |
#write_version ⇒ Object
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 |