Class: Syslibgem::CLI

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

Overview

The user cli usin thor

Instance Method Summary collapse

Instance Method Details

#ask_to_learn(gems) ⇒ Object



49
50
51
52
53
54
# File 'lib/syslibgem.rb', line 49

def ask_to_learn(gems)
  puts 'I don\'t know about these gems would
   you like to help me? (y/n)'.yellow
  puts gems.join(', ').red
  learn(gems) if input
end

#inputObject



71
72
73
74
75
76
77
78
79
# File 'lib/syslibgem.rb', line 71

def input
  STDOUT.flush
  input = STDIN.gets.chomp
  if 'yY'.include? input
    true
  else
    false
  end
end

#install_lunix(libraries) ⇒ Object



35
36
37
38
39
40
# File 'lib/syslibgem.rb', line 35

def install_lunix(libraries)
  libraries.each do |pkg|
    puts "Do you want to install #{pkg} library? (y/n)".blue
    system("sudo apt-get -y install #{pkg}") if input
  end
end

#install_mac(libraries) ⇒ Object



42
43
44
45
46
47
# File 'lib/syslibgem.rb', line 42

def install_mac(libraries)
  libraries.each do |pkg|
    puts "Do you want to install #{pkg} library? (y/n)".blue
    system("bower install #{pkg} --no-interactive") if input
  end
end

#learn(gems) ⇒ Object



56
57
58
59
60
61
# File 'lib/syslibgem.rb', line 56

def learn(gems)
  gems.each do |gem|
    puts "Do you want teach me #{gem} libraries? (y/n)".blue
    push_new_gem(gem) if input
  end
end

#push_new_gem(gem) ⇒ Object



63
64
65
66
67
68
69
# File 'lib/syslibgem.rb', line 63

def push_new_gem(gem)
  puts 'add the dependencies names sperated by comma'.blue
  STDOUT.flush
  line = STDIN.gets.chomp
  deps = line.delete(' ').split(',')
  Server.create(gem, deps) unless deps.empty?
end

#showObject



12
13
14
15
16
17
18
19
20
# File 'lib/syslibgem.rb', line 12

def show
  gems = Bundler.load.specs.map(&:name)
  respose = Server.load(gems)
  libraries = respose['data']['dependencies']
  unknown = respose['data']['unknown']
  os_name = Server.find_os
  system_libraries_install(os_name, libraries)
  ask_to_learn(unknown)
end

#system_libraries_install(os_name, libraries) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/syslibgem.rb', line 22

def system_libraries_install(os_name, libraries)
  puts 'Your system needs to install these libraries
  to be able to run bundle install'.yellow
  puts libraries.join(', ').red
  if os_name == 'lunix'
    install_lunix(libraries)
  elsif os_name == 'mac'
    install_mac(libraries)
  else
    abort 'sorry your os is not supported'.red
  end
end