Class: Xcbump::Bump

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

Instance Method Summary collapse

Instance Method Details

#bump_version(version_type) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/xcbump.rb', line 26

def bump_version(version_type)
  file_path              = File.join(Dir.pwd, project_name, "#{project_name}-Info.plist")
  info_plist             = Plist::parse_xml(file_path)
  current_version_string = info_plist['CFBundleShortVersionString']
  current_build_string   = info_plist['CFBundleVersion']
  puts "Current version: #{current_version_string} (#{current_build_string})"

  case version_type
  when :major
    version_index = 0
  when :minor
    version_index = 1
  when :patch
    version_index = 2
  else
    version_index = 3
  end

  current_build = current_build_string.split('.').map(&:to_i)
  new_build = []
  current_build.each_index do |index|
    current_number = current_build[index]

    if index < version_index
      new_number = current_number
    elsif index > version_index
      new_number = 0
    else
      new_number = current_number + 1
    end

    new_build[index] = new_number
  end

  new_version_string = new_build[0..-2].join('.')
  new_build_string = new_build.join('.')
  info_plist['CFBundleShortVersionString'] = new_version_string
  info_plist['CFBundleVersion'] = new_build_string

  puts "New version: #{new_version_string} (#{new_build_string})"

  File.write(file_path, info_plist.to_plist)
end

#config_file_pathObject



13
14
15
# File 'lib/xcbump.rb', line 13

def config_file_path
  File.join(Dir.pwd, 'xcbump.yml')
end

#configureObject



8
9
10
11
# File 'lib/xcbump.rb', line 8

def configure
  File.write(config_file_path, { project: ask('Project name?  ') }.to_yaml)
  puts "Config file written to '#{config_file_path}'."
end

#project_nameObject



17
18
19
# File 'lib/xcbump.rb', line 17

def project_name
  @project_name ||= project_name_from_config
end

#project_name_from_configObject



21
22
23
24
# File 'lib/xcbump.rb', line 21

def project_name_from_config
  config = YAML.load(File.read(config_file_path))
  config[:project]
end