Module: Ghrepo

Extended by:
Ghrepo
Included in:
Ghrepo
Defined in:
lib/ghrepo.rb,
lib/ghrepo/version.rb

Constant Summary collapse

VERSION =
"0.0.4"

Instance Method Summary collapse

Instance Method Details

#add_html(repo_name, git_url) ⇒ Object



74
75
76
77
78
79
80
81
82
83
# File 'lib/ghrepo.rb', line 74

def add_html(repo_name, git_url)
  app_dir = "./#{repo_name}"
  latest_ghrepo_gem = (Dir.entries(ENV["GEM_HOME"] + "/gems")).select {|l| l.start_with?('ghrep')}.last
  html5_file = ENV["GEM_HOME"] += "/gems/" + latest_ghrepo_gem + "/lib/html5-boilerplate.html"
  Dir.chdir(app_dir)
  `cp #{html5_file} ./index.html`
  `git add .`
  `git commit -m "boilerplate html"`
  `git push -u origin master`
end

#add_rails(repo_name, git_url) ⇒ Object



90
91
92
93
94
95
96
# File 'lib/ghrepo.rb', line 90

def add_rails(repo_name, git_url)
  puts "\nbuilding your rails app...."
  `rails new "#{repo_name}"`
  Dir.chdir(repo_name)
  `git init`
  `git remote add origin "#{git_url}"`
end

#include_rails(args, repo_name, git_url) ⇒ Object



85
86
87
88
# File 'lib/ghrepo.rb', line 85

def include_rails(args, repo_name, git_url)
  add_rails(repo_name, git_url)
  push_rails
end

#prompt_passwordObject



48
49
50
51
# File 'lib/ghrepo.rb', line 48

def prompt_password
  print "password > "
  password = STDIN.noecho(&:gets).chomp
end

#prompt_usernameObject



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

def prompt_username
  print "github username > "
  username = STDIN.gets.chomp
end

#push_railsObject



98
99
100
101
102
# File 'lib/ghrepo.rb', line 98

def push_rails
  `git add .`
  `git commit -m "boilerplate rails"`
  `git push -u origin master`
end

#set_credentials(args) ⇒ Object



70
71
72
# File 'lib/ghrepo.rb', line 70

def set_credentials(args)
  {url: set_url(args), username: set_username, password: set_password}
end

#set_passwordObject



66
67
68
# File 'lib/ghrepo.rb', line 66

def set_password
  ENV['GHREPO_KEY'] || prompt_password
end

#set_url(args) ⇒ Object



53
54
55
# File 'lib/ghrepo.rb', line 53

def set_url(args)
  ENV['GHREPO_SSH'] || args.include?('-ssh') ? 'ssh_url' : 'clone_url'
end

#set_usernameObject



57
58
59
# File 'lib/ghrepo.rb', line 57

def set_username
  ENV['GHREPO_USERNAME'] || prompt_username
end

#start(args) ⇒ Object



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
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ghrepo.rb', line 11

def start(args)
  if args.any?
    repo_name = args.pop
    credentials = set_credentials(args)
    response = `curl -u "#{credentials[:username]}:#{credentials[:password]}" https://api.github.com/user/repos -d '{"name":"'#{repo_name}'"}'`
    git_url = JSON.parse(response)[credentials[:url]]

    args.include?('-rails') ? include_rails(args, repo_name, git_url) : `git clone "#{git_url}"`
    add_html(repo_name, git_url) if args.include?('-html')

  else
    puts "RTFM dummy!"
    puts "      \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2584\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2584\u2591\u2591\u2591\u2591\n      \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u258C\u2592\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2584\u2580\u2592\u258C\u2591\u2591\u2591\n      \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u258C\u2592\u2592\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2584\u2580\u2592\u2592\u2592\u2590\u2591\u2591\u2591\n      \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2590\u2584\u2580\u2592\u2592\u2580\u2580\u2580\u2580\u2584\u2584\u2584\u2580\u2592\u2592\u2592\u2592\u2592\u2590\u2591\u2591\u2591\n      \u2591\u2591\u2591\u2591\u2591\u2584\u2584\u2580\u2592\u2591\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2588\u2592\u2592\u2584\u2588\u2592\u2590\u2591\u2591\u2591\n      \u2591\u2591\u2591\u2584\u2580\u2592\u2592\u2592\u2591\u2591\u2591\u2592\u2592\u2592\u2591\u2591\u2591\u2592\u2592\u2592\u2580\u2588\u2588\u2580\u2592\u258C\u2591\u2591\u2591\n      \u2591\u2591\u2590\u2592\u2592\u2592\u2584\u2584\u2592\u2592\u2592\u2592\u2591\u2591\u2591\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2580\u2584\u2592\u2592\u258C\u2591\u2591\n      \u2591\u2591\u258C\u2591\u2591\u258C\u2588\u2580\u2592\u2592\u2592\u2592\u2592\u2584\u2580\u2588\u2584\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2588\u2592\u2590\u2591\u2591\n      \u2591\u2590\u2591\u2591\u2591\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u258C\u2588\u2588\u2580\u2592\u2592\u2591\u2591\u2591\u2592\u2592\u2592\u2580\u2584\u258C\u2591\n      \u2591\u258C\u2591\u2592\u2584\u2588\u2588\u2584\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2591\u2591\u2591\u2591\u2591\u2591\u2592\u2592\u2592\u2592\u258C\u2591\n      \u2580\u2592\u2580\u2590\u2584\u2588\u2584\u2588\u258C\u2584\u2591\u2580\u2592\u2592\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2592\u2592\u2592\u2590\u2591\n      \u2590\u2592\u2592\u2590\u2580\u2590\u2580\u2592\u2591\u2584\u2584\u2592\u2584\u2592\u2592\u2592\u2592\u2592\u2592\u2591\u2592\u2591\u2592\u2591\u2592\u2592\u2592\u2592\u258C\n      \u2590\u2592\u2592\u2592\u2580\u2580\u2584\u2584\u2592\u2592\u2592\u2584\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2591\u2592\u2591\u2592\u2591\u2592\u2592\u2590\u2591\n      \u2591\u258C\u2592\u2592\u2592\u2592\u2592\u2592\u2580\u2580\u2580\u2592\u2592\u2592\u2592\u2592\u2592\u2591\u2592\u2591\u2592\u2591\u2592\u2591\u2592\u2592\u2592\u258C\u2591\n      \u2591\u2590\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2591\u2592\u2591\u2592\u2591\u2592\u2592\u2584\u2592\u2592\u2590\u2591\u2591\n      \u2591\u2591\u2580\u2584\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2591\u2592\u2591\u2592\u2591\u2592\u2584\u2592\u2592\u2592\u2592\u258C\u2591\u2591\n      \u2591\u2591\u2591\u2591\u2580\u2584\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2584\u2584\u2584\u2580\u2592\u2592\u2592\u2592\u2584\u2580\u2591\u2591\u2591\n      \u2591\u2591\u2591\u2591\u2591\u2591\u2580\u2584\u2584\u2584\u2584\u2584\u2584\u2580\u2580\u2580\u2592\u2592\u2592\u2592\u2592\u2584\u2584\u2580\u2591\u2591\u2591\u2591\u2591\n      \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2580\u2580\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\n    eos\n    puts \"such moron very dumb\"\n  end\nend\n"