Module: InstallGemLocal::CopyGem

Included in:
Action
Defined in:
lib/install_gem_local/action/copy_gem.rb

Instance Method Summary collapse

Instance Method Details

#choose_copy_folderObject



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/install_gem_local/action/copy_gem.rb', line 5

def choose_copy_folder
  options = {
    'a' => { 'value' => 'desktop', 'display' => 'Desktop' },
    'b' => { 'value' => 'downloads', 'display' => 'Downloads' },
    'c' => { 'value' => 'documents', 'display' => 'Documents' },
    '/' => { 'value' => 'exit', 'display' => 'Exit' }
  }

  InstallGemLocal::Helper.prompt_options(
    flash_message: InstallGemLocal::Helper.flash_message(title: 'Choose Folder to Copy'),
    options: options
  )
end

#copy_file_to_path(file_name) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/install_gem_local/action/copy_gem.rb', line 33

def copy_file_to_path(file_name)
  return if file_name == 'exit'

  folder_name = choose_copy_folder
  puts "Copying gem to #{folder_name}"

  case folder_name
  when 'desktop'
    tty_command.run("cp #{file_name} ~/Desktop")
  when 'downloads'
    tty_command.run("cp #{file_name} ~/Downloads")
  when 'documents'
    tty_command.run("cp #{file_name} ~/Documents")
  end
end

#copy_gemObject



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/install_gem_local/action/copy_gem.rb', line 19

def copy_gem
  puts ''
  puts 'Copy Gem'.green
  files_exists = file_names

  if files_exists.count > 1
    copy_file_to_path(multiple_version_selection)
  elsif files_exists.count == 1
    copy_file_to_path(files_exists.first)
  else
    ap 'Gem not exist'
  end
end