Class: ChocTop::VersionHelper
- Inherits:
-
Object
- Object
- ChocTop::VersionHelper
- Defined in:
- lib/choctop/version_helper.rb
Instance Attribute Summary collapse
-
#build ⇒ Object
readonly
Returns the value of attribute build.
-
#info_plist_path ⇒ Object
Returns the value of attribute info_plist_path.
-
#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
- #info_plist ⇒ Object
-
#initialize(info_plist_path) ⇒ VersionHelper
constructor
A new instance of VersionHelper.
- #parse_version ⇒ Object
- #to_s ⇒ Object
- #update_to(major, minor, patch, build = nil) ⇒ Object
- #write ⇒ Object
Constructor Details
#initialize(info_plist_path) ⇒ VersionHelper
Returns a new instance of VersionHelper.
6 7 8 9 10 11 12 13 |
# File 'lib/choctop/version_helper.rb', line 6 def initialize(info_plist_path) self.info_plist_path = info_plist_path parse_version if block_given? yield self write end end |
Instance Attribute Details
#build ⇒ Object (readonly)
Returns the value of attribute build.
4 5 6 |
# File 'lib/choctop/version_helper.rb', line 4 def build @build end |
#info_plist_path ⇒ Object
Returns the value of attribute info_plist_path.
3 4 5 |
# File 'lib/choctop/version_helper.rb', line 3 def info_plist_path @info_plist_path end |
#major ⇒ Object (readonly)
Returns the value of attribute major.
4 5 6 |
# File 'lib/choctop/version_helper.rb', line 4 def major @major end |
#minor ⇒ Object (readonly)
Returns the value of attribute minor.
4 5 6 |
# File 'lib/choctop/version_helper.rb', line 4 def minor @minor end |
#patch ⇒ Object (readonly)
Returns the value of attribute patch.
4 5 6 |
# File 'lib/choctop/version_helper.rb', line 4 def patch @patch end |
Instance Method Details
#bump_major ⇒ Object
36 37 38 39 40 41 |
# File 'lib/choctop/version_helper.rb', line 36 def bump_major @major += 1 @minor = 0 @patch = 0 @build = nil end |
#bump_minor ⇒ Object
43 44 45 46 47 |
# File 'lib/choctop/version_helper.rb', line 43 def bump_minor @minor += 1 @patch = 0 @build = nil end |
#bump_patch ⇒ Object
49 50 51 52 |
# File 'lib/choctop/version_helper.rb', line 49 def bump_patch @patch += 1 @build = nil end |
#info_plist ⇒ Object
15 16 17 |
# File 'lib/choctop/version_helper.rb', line 15 def info_plist @info_plist ||= OSX::NSDictionary.dictionaryWithContentsOfFile(info_plist_path) || {} end |
#parse_version ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/choctop/version_helper.rb', line 19 def parse_version # http://rubular.com/regexes/10467 -> 3.5.4.a1 # http://rubular.com/regexes/10468 -> 3.5.4 # regex on nsstring is broken so convert it to a ruby string if info_plist['CFBundleVersion'].to_s =~ /^(\d+)\.(\d+)\.?(\d+)?(?:\.(.*?))?$/ @major = $1.to_i @minor = $2.to_i @patch = $3.to_i @build = $4 else @major = 0 @minor = 0 @patch = 0 @build = nil end end |
#to_s ⇒ Object
67 68 69 |
# File 'lib/choctop/version_helper.rb', line 67 def to_s [major, minor, patch, build].compact.join('.') end |
#update_to(major, minor, patch, build = nil) ⇒ Object
54 55 56 57 58 59 |
# File 'lib/choctop/version_helper.rb', line 54 def update_to(major, minor, patch, build=nil) @major = major @minor = minor @patch = patch @build = build end |
#write ⇒ Object
61 62 63 64 65 |
# File 'lib/choctop/version_helper.rb', line 61 def write info_plist['CFBundleVersion'] = to_s info_plist['CFBundleShortVersionString'] = to_s info_plist.writeToFile_atomically(info_plist_path,true) end |