Class: Rover
Overview
Rover.new rover.list_configs #=> hash rover.install_configs #=> execute on hash above TODO rover.run TODO rover.update_from_git TODO rover.authors_from_git
Constant Summary collapse
- CONFIG_FILE_NAMES =
{ "npm" => 'package.json', 'bundle' => 'Gemfile', 'pip' => 'requirements.txt' }
Instance Attribute Summary collapse
-
#pids_created ⇒ Object
Returns the value of attribute pids_created.
-
#start_directory ⇒ Object
Returns the value of attribute start_directory.
Instance Method Summary collapse
- #config_env(config_type) ⇒ Object
- #config_env_bundle ⇒ Object
- #config_env_npm ⇒ Object
- #config_env_pip ⇒ Object
-
#initialize ⇒ Rover
constructor
A new instance of Rover.
- #install_configs ⇒ Object
- #list_configs ⇒ Object
- #pretty_print_configs ⇒ Object
Methods included from Utils
Methods included from Logging
Constructor Details
#initialize ⇒ Rover
Returns a new instance of Rover.
59 60 61 62 63 64 |
# File 'lib/rover.rb', line 59 def initialize @start_directory = Dir.pwd @pids_created = [] puts "Rover is starting in #{@start_directory}" end |
Instance Attribute Details
#pids_created ⇒ Object
Returns the value of attribute pids_created.
51 52 53 |
# File 'lib/rover.rb', line 51 def pids_created @pids_created end |
#start_directory ⇒ Object
Returns the value of attribute start_directory.
51 52 53 |
# File 'lib/rover.rb', line 51 def start_directory @start_directory end |
Instance Method Details
#config_env(config_type) ⇒ Object
88 89 90 91 |
# File 'lib/rover.rb', line 88 def config_env config_type return nil unless config_type self.send("config_env_#{config_type}") end |
#config_env_bundle ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/rover.rb', line 102 def config_env_bundle # nothing to do unless which('bundle') exec_cmd "gem install bundler" unless which('bundle') puts "Please install Bundler (gem install bundler) to continue installing dependencies" return false end end true end |
#config_env_npm ⇒ Object
93 94 95 96 97 98 99 100 |
# File 'lib/rover.rb', line 93 def config_env_npm unless which('npm') puts "Please install npm to continue installing dependencies" return false end true end |
#config_env_pip ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/rover.rb', line 115 def config_env_pip ['virtualenv'].each do |exe| unless which(exe) raise "you're fucked; missing #{exe}. please install first" end end python_dir = "#{@start_directory}/.python" exec_cmd "mkdir -p #{python_dir}" exec_cmd "virtualenv #{python_dir}" ENV['PATH'] = "#{python_dir}/bin:#{ENV['PATH']}" ENV['PYTHONPATH'] = "" true end |
#install_configs ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/rover.rb', line 131 def install_configs discovered_config_files = discover_config_files if discovered_config_files.empty? puts "Rover did not find any configuration files in this project" else puts "Rover found #{discovered_config_files.size} configuration files".underline puts "\n" discovered_config_files.each do |config_file_name,config_parts| puts "Installing Config: #{config_file_name}".colorize( :color => :white, :background => :blue ) next unless config_env(config_parts['config_type']) cmd = "#{config_parts['config_type']} " case config_parts['config_type'] when 'pip' cmd += "install -r #{config_parts['config_file']}" when 'bundle' cmd += "install" when 'npm' cmd += "install" else logger.info "Unknown Config Type: #{config_parts['config_type']}" next end change_dir(config_parts['config_path']) exec_cmd(cmd) puts "\n\n" end puts "If you are using a Python project please add the following lines to a .env file in the project's root directory".colorize( :color => :white, :background => :blue ) puts "PATH=#{@start_directory}/.python/bin:$PATH".colorize( :color => :red).underline puts "PYTHONPATH=''".colorize( :color => :red).underline puts "Finished attempting to install config files. Moving back to the starting directory".colorize( :color => :white, :background => :blue ) change_dir(@start_directory) end end |
#list_configs ⇒ Object
66 67 68 |
# File 'lib/rover.rb', line 66 def list_configs discover_config_files end |
#pretty_print_configs ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/rover.rb', line 70 def pretty_print_configs configs = discover_config_files out = "Rover found #{configs.size} dependency configurations\n" index_count = 1 discover_config_files.each do |config,config_parts| out += "--\n" out += "#{index_count}: #{config}\n" out += "#{index_count}: Type: #{config_parts['config_type']}\n" out += "#{index_count}: File: #{config_parts['config_file']}\n" out += "#{index_count}: Path: #{config_parts['config_path']}\n" index_count+=1 end puts out.colorize(:color => :blue) end |