Class: Veyron
- Inherits:
-
Object
- Object
- Veyron
- Defined in:
- lib/veyron.rb
Instance Attribute Summary collapse
-
#github_username ⇒ Object
Returns the value of attribute github_username.
-
#project_dir ⇒ Object
Returns the value of attribute project_dir.
-
#project_name ⇒ Object
Returns the value of attribute project_name.
-
#veyron_dir ⇒ Object
Returns the value of attribute veyron_dir.
-
#visibility ⇒ Object
Returns the value of attribute visibility.
Instance Method Summary collapse
- #create_rails_project ⇒ Object
- #create_repo ⇒ Object
- #get_user_input ⇒ Object
- #initial_commit ⇒ Object
-
#initialize ⇒ Veyron
constructor
A new instance of Veyron.
- #vagrant_setup ⇒ Object
- #vagrant_ssh ⇒ Object
- #vagrant_up ⇒ Object
Constructor Details
#initialize ⇒ Veyron
Returns a new instance of Veyron.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/veyron.rb', line 9 def initialize @veyron_dir = File.(File.dirname(__FILE__)) get_user_input create_repo say("**************************************************************") say(" THIS IS GOING TO TAKE ABOUT 20 MINS\n") say(" GO MAKE A SANDWICH\n") say("**************************************************************") say("CREATING NEW RAILS PROJECT AT #{@project_path}") create_rails_project say("CREATING VAGRANT DIRECTORIES AND COPYING COOKBOOKS") vagrant_setup say("MAKING INITIAL COMMIT TO GITHUB") initial_commit say("**************************************************************") say(" VAGRANT UP\n") say("**************************************************************") vagrant_up say("**************************************************************") say(" VAGRANT SSH\n") say("**************************************************************") vagrant_ssh say("**************************************************************") say(" NOW, JUST cd TO /srv/PROJECT_NAME\n") say(" AND rails s\n") say("**************************************************************") end |
Instance Attribute Details
#github_username ⇒ Object
Returns the value of attribute github_username.
7 8 9 |
# File 'lib/veyron.rb', line 7 def github_username @github_username end |
#project_dir ⇒ Object
Returns the value of attribute project_dir.
7 8 9 |
# File 'lib/veyron.rb', line 7 def project_dir @project_dir end |
#project_name ⇒ Object
Returns the value of attribute project_name.
7 8 9 |
# File 'lib/veyron.rb', line 7 def project_name @project_name end |
#veyron_dir ⇒ Object
Returns the value of attribute veyron_dir.
7 8 9 |
# File 'lib/veyron.rb', line 7 def veyron_dir @veyron_dir end |
#visibility ⇒ Object
Returns the value of attribute visibility.
7 8 9 |
# File 'lib/veyron.rb', line 7 def visibility @visibility end |
Instance Method Details
#create_rails_project ⇒ Object
64 65 66 67 |
# File 'lib/veyron.rb', line 64 def create_rails_project FileUtils.cd "#{@project_dir}" system("rails new #{@project_name} -d mysql -q") end |
#create_repo ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/veyron.rb', line 49 def create_repo pw = ask("Enter password for GitHub accout #{@github_username}: ") { |q| q.echo = false } response = Net::HTTP.post_form(URI.parse("http://#{@github_username}:#{pw}@github.com/api/v2/json/repos/create"), {"name" => @project_name, "public" => @visibility}) pw = nil case @visibility when 1 say("Created PUBLIC GitHub repo #{@project_name} for #{@github_username}") when 0 say("Created PRIVATE GitHub repo #{@project_name} for #{@github_username}") end return end |
#get_user_input ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/veyron.rb', line 37 def get_user_input @project_dir = ask("Where do you keep your projects? ex. /Users/chris/Projects: ") @project_name = ask("Project Name ex. my_new_project: ") @project_name = @project_name.squeeze.strip.gsub(" ", "_").downcase @project_path = "#{@project_dir}/#{@project_name}" @github_username = ask("GitHub username: ") @visibility = ask("Is this going to be a PRIVATE REPO? ( y / n )? ") { |q| q.validate = lambda {|r| r == 'y' || r == 'n'}; q.responses[:not_valid] = "Please enter 'y' or 'n'"} @visibility = @visibility == 'y' ? 0 : 1 return end |
#initial_commit ⇒ Object
87 88 89 90 91 92 93 94 |
# File 'lib/veyron.rb', line 87 def initial_commit FileUtils.cd "#{@project_path}" system("git init") system("git add .") system("git commit -q -m 'initial commit'") system("git remote add origin [email protected]:#{@github_username}/#{@project_name}.git") system("git push origin master") end |
#vagrant_setup ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/veyron.rb', line 69 def vagrant_setup FileUtils.cd "#{@project_path}" FileUtils.mkdir_p "vagrant" FileUtils.mkdir_p "data/cookbooks" FileUtils.mkdir_p "data/roles" FileUtils.cd "vagrant" FileUtils.cp "#{@veyron_dir}/../Vagrantfile", "#{@project_path}/vagrant/Vagrantfile" default_file = File.read("#{@project_path}/vagrant/Vagrantfile") updated_file = default_file.gsub("$PROJECT_NAME", "#{@project_name.downcase}") File.open("#{@project_path}/vagrant/Vagrantfile", "w") {|f| f.puts updated_file} FileUtils.cp_r "#{@veyron_dir}/../cookbooks", "#{@project_path}/data/" FileUtils.cp_r "#{@veyron_dir}/../roles", "#{@project_path}/data/" default_file = File.read("#{@project_path}/data/cookbooks/bundler/recipes/default.rb") updated_file = default_file.gsub("$PROJECT_NAME", "#{@project_name.downcase}") File.open("#{@project_path}/data/cookbooks/bundler/recipes/default.rb", "w") {|f| f.puts updated_file} end |
#vagrant_ssh ⇒ Object
101 102 103 104 |
# File 'lib/veyron.rb', line 101 def vagrant_ssh FileUtils.cd "#{@project_path}/vagrant" system("vagrant ssh #{@project_name}") end |
#vagrant_up ⇒ Object
96 97 98 99 |
# File 'lib/veyron.rb', line 96 def vagrant_up FileUtils.cd "#{@project_path}/vagrant" system("vagrant up #{@project_name}") end |