Skip to content

Instantly share code, notes, and snippets.

@ulhas
Created March 20, 2016 03:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ulhas/e2364d80078755382982 to your computer and use it in GitHub Desktop.
Save ulhas/e2364d80078755382982 to your computer and use it in GitHub Desktop.
Fastlane helper file for HyperTrack iOS
module Fastlane
module Helper
class HTHelper
attr_accessor :path
attr_accessor :ht_content
attr_accessor :version_regex
attr_accessor :version_match
attr_accessor :version_value
def initialize()
version_var_name = 'HTSDKVersion'
@path = 'HTCommon/HTCommon/HyperTrack.h'
@version_regex = /(?<begin>.*#{version_var_name}\s*=\s*@")(?<value>(?<major>[0-9]+)(\.(?<minor>[0-9]+))?(\.(?<patch>[0-9]+))?)(?<end>";)/i
File.open(@path, "r") do |file|
parse(file.read)
end unless Helper.test?
end
def parse(ht_content)
@ht_content = ht_content
@version_match = @version_regex.match(@ht_content)
raise "Could not find version in ht content '#{@ht_content}'".red if @version_match.nil?
@version_value = @version_match[:value]
end
def get_version()
@version_value
end
def bump_version(bump_type)
major = version_match[:major].to_i
minor = version_match[:minor].to_i || 0
patch = version_match[:patch].to_i || 0
case bump_type
when 'patch'
patch += 1
when 'minor'
minor += 1
patch = 0
when 'major'
major += 1
minor = 0
patch = 0
end
@version_value = "#{major}.#{minor}.#{patch}"
end
def update_version(version = nil)
new_version = version || @version_value
updated_ht_content = @ht_content.gsub(@version_regex, "#{@version_match[:begin]}#{new_version}#{@version_match[:end]}")
File.open(@path, "w") do |file|
file.puts updated_ht_content
end unless Helper.test?
updated_ht_content
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment