Class: Gct::Command::Update::Version

Inherits:
Gct::Command::Update show all
Defined in:
lib/gct/command/update/version.rb

Instance Method Summary collapse

Methods inherited from Gct::Command

#auto_add_tag, #check_branch_can_be_update, #config_gitlab, #current_branch, #file_contents, #get_project, #gitlab_error, options, run

Constructor Details

#initialize(argv) ⇒ Version

Returns a new instance of Version.



16
17
18
19
20
21
22
23
24
# File 'lib/gct/command/update/version.rb', line 16

def initialize(argv)
  config_gitlab
  @name = argv.shift_argument
  @version = argv.shift_argument
  name = @name ||= "iLife"
  @project_id = "#{Constant.NameSpace}#{name}"
  @file = "#{name}.xcodeproj/project.pbxproj"
  super
end

Instance Method Details

#edit_file(content, version) ⇒ Object



52
53
54
# File 'lib/gct/command/update/version.rb', line 52

def edit_file(content, version)
  Gitlab.edit_file(@project_id, @file, @branch, content, "@config 更新版本号:#{version}")
end

#runObject



30
31
32
33
# File 'lib/gct/command/update/version.rb', line 30

def run
  @branch = current_branch
  update_version
end

#update_versionObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/gct/command/update/version.rb', line 35

def update_version
  puts @project_id
  puts @file
  puts @branch
  content = file_contents(@project_id, @file, @branch)
  puts content
  if check_branch_can_be_update('release')
    content = file_contents(@project_id, @file, @branch)
    version_var_name = 'MARKETING_VERSION = '
    version_regex = /(?<=#{version_var_name})\w.*(?=;)/
    version_match = version_regex.match(content)
    version = @version ||= auto_add_tag(version_match)
    updated_content = content.gsub(version_regex, version)
    edit_file(updated_content, version)
  end
end

#validate!Object



26
27
28
# File 'lib/gct/command/update/version.rb', line 26

def validate!
    super
end