Class: ChocTop::VersionHelper

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#buildObject (readonly)

Returns the value of attribute build.



4
5
6
# File 'lib/choctop/version_helper.rb', line 4

def build
  @build
end

#info_plist_pathObject

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

#majorObject (readonly)

Returns the value of attribute major.



4
5
6
# File 'lib/choctop/version_helper.rb', line 4

def major
  @major
end

#minorObject (readonly)

Returns the value of attribute minor.



4
5
6
# File 'lib/choctop/version_helper.rb', line 4

def minor
  @minor
end

#patchObject (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_majorObject



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_minorObject



43
44
45
46
47
# File 'lib/choctop/version_helper.rb', line 43

def bump_minor
  @minor += 1
  @patch = 0
  @build = nil
end

#bump_patchObject



49
50
51
52
# File 'lib/choctop/version_helper.rb', line 49

def bump_patch
  @patch += 1
  @build = nil
end

#info_plistObject



15
16
17
# File 'lib/choctop/version_helper.rb', line 15

def info_plist
  @info_plist ||= OSX::NSDictionary.dictionaryWithContentsOfFile(info_plist_path) || {}
end

#parse_versionObject



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_sObject



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

#writeObject



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