Class: Pbmenv::CreateVersionService

Inherits:
Object
  • Object
show all
Defined in:
lib/pbmenv/services/create_version_service.rb

Defined Under Namespace

Classes: AlreadyCreatedError, NotSupportVersionError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version:, use_option:, enable_pbm_cloud:) ⇒ CreateVersionService

Returns a new instance of CreateVersionService.



10
11
12
13
14
# File 'lib/pbmenv/services/create_version_service.rb', line 10

def initialize(version: , use_option: , enable_pbm_cloud: )
  self.version = version
  self.use_option = use_option
  self.enable_pbm_cloud = enable_pbm_cloud
end

Instance Attribute Details

#enable_pbm_cloudObject

Returns the value of attribute enable_pbm_cloud.



8
9
10
# File 'lib/pbmenv/services/create_version_service.rb', line 8

def enable_pbm_cloud
  @enable_pbm_cloud
end

#use_optionObject

Returns the value of attribute use_option.



8
9
10
# File 'lib/pbmenv/services/create_version_service.rb', line 8

def use_option
  @use_option
end

#versionObject

Returns the value of attribute version.



8
9
10
# File 'lib/pbmenv/services/create_version_service.rb', line 8

def version
  @version
end

Instance Method Details

#execute!Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/pbmenv/services/create_version_service.rb', line 16

def execute!
  pathname = VersionPathname.new(version)
  if File.exist?(pathname.version_path)
    raise AlreadyCreatedError
  end

  begin
    download_src(version)
    build_app_file
    create_if_miss_shared_dir
    create_if_miss_device_id_file
    link_device_id_file(version: version)
    create_if_miss_current_dir(version: version)
  rescue DownloadSrcService::DownloadError
    puts "Download failed. Check the version name."
    raise NotSupportVersionError
  rescue => e
    Helper.system_and_puts "rm -rf #{pathname.version_path}"
    raise
  ensure
    if Dir.exist?(pathname.src_pbm_path)
      Helper.system_and_puts "rm -rf #{pathname.src_pbm_path}"
    end
  end

  return true
end