Class: IOSBox::IOSBox::Version

Inherits:
Object
  • Object
show all
Defined in:
lib/ios-box/iosbox.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(iosbox) ⇒ Version

Returns a new instance of Version.



70
71
72
# File 'lib/ios-box/iosbox.rb', line 70

def initialize(iosbox)
  @iosbox = iosbox
end

Instance Attribute Details

#iosboxObject (readonly)

Returns the value of attribute iosbox.



68
69
70
# File 'lib/ios-box/iosbox.rb', line 68

def iosbox
  @iosbox
end

Instance Method Details

#[](v) ⇒ Object



101
102
103
104
# File 'lib/ios-box/iosbox.rb', line 101

def [](v)
  @version ||= load
  @version[v]
end

#[]=(v, s) ⇒ Object



106
107
108
109
# File 'lib/ios-box/iosbox.rb', line 106

def []=(v, s)
  @version ||= load
  @version[v] = s
end

#bump_build(buildnum = nil) ⇒ Object



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/ios-box/iosbox.rb', line 154

def bump_build(buildnum = nil)
  # Fetch current build number (project version)
  pl = Plist::parse_xml(iosbox.plist)
  # pl["CFBundleShortVersionString"] = verstr
  # pl.save_plist(plist)

  if buildnum.nil?
    build = (pl["IBBuildNumber"] || 0) + 1
  else
    build = buildnum
  end

  pl["IBBuildNumber"] = build
  pl["CFBundleVersion"] = bundle_version
  pl.save_plist(iosbox.plist)

  # Commit plist
  if iosbox.config['autocommit']
    iosbox.git.add iosbox.plist
    iosbox.git.commit "Bumped build number"
  end


  puts "Build number increased to #{build}"
end

#bump_marketing(type = :patch) ⇒ Object



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# File 'lib/ios-box/iosbox.rb', line 188

def bump_marketing(type = :patch)
  load

  if type == :major
    @version[:patch] = nil
    @version[:minor] = 0
    @version[:major] += 1
  elsif type == :minor
    @version[:patch] = nil
    @version[:minor] += 1
  elsif type == :patch
    @version[:patch] = (@version[:patch] || 0) + 1
  end

  pl = Plist::parse_xml(iosbox.plist)
  pl["CFBundleShortVersionString"] = marketing_version
  pl.save_plist(iosbox.plist)

  puts "New marketing version #{marketing_version}"
end

#bundle_versionObject



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/ios-box/iosbox.rb', line 120

def bundle_version
  load unless @version

  # Build our components
  comp = {
    "M" => @version[:major],
    "m" => @version[:minor],
    "p" => @version[:patch],
    "P" => @version[:patch] ? ".#{@version[:patch]}" : "",
    "b" => @version[:build],
    "S" => marketing_version,
    "V" => @version[:major] * 10 + @version[:minor],
    "v" => @version[:major] * 100 + @version[:minor] * 10 + (@version[:patch] ? @version[:patch] : 0),
    "x" => begin
    prj_begin = Time.now
    if (iosbox.config.first_revision)
      prj_begin = iosbox.git.commit(iosbox.config.first_revision).authored_date
    elsif (iosbox.config.first_date)
      prj_begin = iosbox.config.first_date
    else
      prj_begin = iosbox.git.log.last.authored_date
    end

    months = ((Time.now.month + 12 * Time.now.year) - (prj_begin.month + 12 * prj_begin.year))
    "%d%02d" % [months, Time.now.day]
    end,
  }
  compre = Regexp.new("[" + comp.keys.join("") + "]")

  @version[:bundle] = (iosbox.config.bundle_version_style || "x").gsub(compre) do |s|
    comp[s]
  end
end

#loadObject



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/ios-box/iosbox.rb', line 74

def load
  # Return cached version
  return @version if @version

  # Detect our commit hash
  # git = Grit::Repo.new(iosbox.project_dir)
  pl = Plist::parse_xml(iosbox.plist)

  # Build normal version hash
  @version  = {
    :short  => pl["CFBundleShortVersionString"],
    :bundle => pl["CFBundleVersion"],
    :commit => iosbox.git.commit("HEAD").id_abbrev,
    :build  => pl["IBBuildNumber"],
  }

  # Build technical version number
  if (m = pl["CFBundleShortVersionString"].match(/(\d+)\.(\d+)(\.(\d+))?/))
    @version[:major] = Integer(m[1]) if m[1]
    @version[:minor] = Integer(m[2]) if m[2]
    @version[:patch] = Integer(m[4]) if m[4]
    @version[:technical] = @version[:major] + @version[:minor] / 100.0 + (@version[:patch] || 0) / 10000.0
  end

  @version
end

#marketing_versionObject



115
116
117
118
# File 'lib/ios-box/iosbox.rb', line 115

def marketing_version
  load unless @version
  "%d.%d%s" % [ @version[:major], @version[:minor], @version[:patch] ? ".#{@version[:patch]}" : "" ]
end

#set_marketing(verstr) ⇒ Object



180
181
182
183
184
185
186
# File 'lib/ios-box/iosbox.rb', line 180

def set_marketing(verstr)
  pl = Plist::parse_xml(iosbox.plist)
  pl["CFBundleShortVersionString"] = verstr
  pl.save_plist(iosbox.plist)

  puts "New marketing version #{marketing_version}"
end

#to_aObject



111
112
113
# File 'lib/ios-box/iosbox.rb', line 111

def to_a
  (@version ||= load).to_a
end