Class: Devtools::DevToolsProject

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

Instance Method Summary collapse

Instance Method Details

#checkIfBrewInstalledObject



141
142
143
144
145
146
147
148
# File 'lib/devtools.rb', line 141

def checkIfBrewInstalled()
  check_brew = %x( which brew )
  if check_brew == "brew not found"
    return false
  else
    return true
  end
end

#checkifCaskInstalledObject



156
157
158
159
160
161
162
163
# File 'lib/devtools.rb', line 156

def checkifCaskInstalled()
  check_cask = %x( brew info cask )
  if check_cask.include? "Not installed"
    return false
  else
    return true
  end
end

#colorize(text, color = "default", bgColor = "default") ⇒ Object



180
181
182
183
184
185
186
187
188
189
190
# File 'lib/devtools.rb', line 180

def colorize(text, color = "default", bgColor = "default")
  colors = {"default" => "38","black" => "30","red" => "31","green" => "32","brown" => "33", "blue" => "34", "purple" => "35",
            "cyan" => "36", "gray" => "37", "dark gray" => "1;30", "light red" => "1;31", "light green" => "1;32", "yellow" => "1;33",
            "light blue" => "1;34", "light purple" => "1;35", "light cyan" => "1;36", "white" => "1;37"}
  bgColors = {"default" => "0", "black" => "40", "red" => "41", "green" => "42", "brown" => "43", "blue" => "44",
              "purple" => "45", "cyan" => "46", "gray" => "47", "dark gray" => "100", "light red" => "101", "light green" => "102",
              "yellow" => "103", "light blue" => "104", "light purple" => "105", "light cyan" => "106", "white" => "107"}
  color_code = colors[color]
  bgColor_code = bgColors[bgColor]
  return "\033[#{bgColor_code};#{color_code}m#{text}\033[0m"
end

#installApp(appname, exitStatus) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/devtools.rb', line 9

def installApp (appname, exitStatus)
  search_output = %x( brew cask search #{appname} )
  if search_output.include? "Exact match"
    puts colorize("Info: Installing #{appname}", "yellow")
    console_output = %x( brew cask install #{appname} )
    puts console_output
  elsif search_output.include? "No Cask found"
    puts colorize("Error: No such app found", "red")
  else
    puts search_output
  end
  if exitStatus == true
    exit
  end
end

#installBrewObject



150
151
152
153
154
# File 'lib/devtools.rb', line 150

def installBrew()
  puts colorize("Info: Installing Brew", "yellow")
  console_output = %x( /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" )
  puts console_output
end

#installCaskObject



165
166
167
168
169
# File 'lib/devtools.rb', line 165

def installCask()
  puts colorize("Info: Installing Cask", "yellow")
  console_output = %x( brew install cask )
  puts console_output
end

#installEnvironment(environment) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/devtools.rb', line 25

def installEnvironment(environment)
  if environment.casecmp("git")
    setupGit()
  elsif environment.casecmp("ruby-on-rails")
    setupRubyOnRails()
  elsif environment.casecmp("postgres")
    setupPostgres()
  elsif environment.casecmp("android")
    setupAndroidStudio()
  elsif environment.casecmp("python")
    setupPython()
  elsif environment.casecmp("python3")
    setupPython3()
  elsif environment.casecmp("node")
    setupNode()
  end
end

#listAppsObject



171
172
173
174
175
176
177
178
# File 'lib/devtools.rb', line 171

def listApps()
  puts colorize("Info: List of apps you can install", "yellow")
  console_output =  %x( brew cask search )
  puts console_output
  puts colorize("Info: List of environment you can setup", "yellow")
  puts "git\nruby-on-rails\npostgres\nandroid\npython\npython3\nnode"
  exit
end

#parseInputObject



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/devtools.rb', line 123

def parseInput()
  params = OpenStruct.new
  OptionParser.new do |opt|
    opt.on('-i', '--install APP_NAME', 'The flag used to indicate the tool that needs to be installed.') { |o| params.app_name = o }
    opt.on('-e', '--environment ENVIRONMENT', 'Path to the file that contains the information about the development environment to setup.') { |o| params.environment = o }
    opt.on('-l', '--list', 'Displays a list of apps that can be installed.') { params.list = "list" }
  end.parse!

  if params.app_name.to_s.strip.length == 0  && params.environment.to_s.strip.length == 0 && params.list.to_s.strip.length == 0
    puts colorize("Error: Missing option", "Red")
    options = %x( dev-tools -h )
    puts options
    exit
  else
    return params
  end
end

#setupAndroidStudioObject



61
62
63
64
65
# File 'lib/devtools.rb', line 61

def setupAndroidStudio()
  puts colorize("Info: Installing Android Studio", "green")
  andrid_console_output = %x( brew cask install android-studio )
  puts andrid_console_output
end

#setupEnvironment(environment) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/devtools.rb', line 94

def setupEnvironment (environment)
  if !File.exists?(environment) then
    puts colorize("Error: Invalid file path", "red")
  elsif !environment.include? ".yml"
    puts colorize("Error: Invalid file type only yml config files are accepted", "red")
  else
    isAppMode = true
    puts colorize("Info: Reading environment", "green")
    env_setup_file = open environment
    env_setup_file.each do |line|
      currentLine = line.to_s.strip
      if currentLine.include? "Apps:"
        isAppMode = true
      elsif currentLine.include? "Environment:"
        isAppMode = false
      end
      if currentLine != "Apps:" && currentLine != "Environment:"
        if isAppMode == true
          installApp(currentLine, false)
        else
          installEnvironment(currentLine)
        end
      end
    end
    env_setup_file.close
  end
  exit
end

#setupGitObject



73
74
75
76
77
# File 'lib/devtools.rb', line 73

def setupGit()
  puts colorize("Info: Installing Git", "green")
  git_console_output = %x( brew install bash curl git )
  puts git_console_output
end

#setupNodeObject



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

def setupNode()
  puts colorize("Info: Installing Node", "green")
  node_console_output = %x( brew install node )
  puts node_console_output
end

#setupPostgresObject



67
68
69
70
71
# File 'lib/devtools.rb', line 67

def setupPostgres()
  puts colorize("Info: Installing Postgres", "green")
  postgres_console_output = %x( brew cask install postgres )
  puts postgres_console_output
end

#setupPythonObject



55
56
57
58
59
# File 'lib/devtools.rb', line 55

def setupPython()
  puts colorize("Info: Installing Python 2.7", "green")
  python_console_output = %x( brew install python )
  puts python_console_output
end

#setupPython3Object



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

def setupPython3()
  puts colorize("Info: Installing Python 3", "green")
  python3_console_output = %x( brew install python3 )
  puts python3_console_output
end

#setupRubyOnRailsObject



79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/devtools.rb', line 79

def setupRubyOnRails()
  puts colorize("Info: Installing RVM", "green")
  gpg_console_output = %x( gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 )
  puts gpg_console_output
  rvm_console_output = %x( \\curl -sSL https://get.rvm.io | bash -s stable )
  puts rvm_console_output
  puts colorize("Info: Installing Ruby", "green")
  ruby_console_output = %x( \\curl -L https://get.rvm.io | bash -s stable --ruby )
  puts ruby_console_output
  puts colorize("Info: Installing Rails", "green")
  rails_console_output = %x( gem install rails )
  puts rails_console_output
  setupPostgres()
end