Class: HerokuWhiz
- Inherits:
-
Object
- Object
- HerokuWhiz
- Defined in:
- lib/heroku_whiz.rb
Instance Method Summary collapse
- #app_url ⇒ Object
- #create ⇒ Object
- #deploy ⇒ Object
-
#initialize(dir: '.', template: 'rack', appname: 'myapp', verbose: true, debug: false) ⇒ HerokuWhiz
constructor
A new instance of HerokuWhiz.
- #local_run ⇒ Object
- #local_testrun ⇒ Object
- #wipe_clean(setup = :local) ⇒ Object
Constructor Details
#initialize(dir: '.', template: 'rack', appname: 'myapp', verbose: true, debug: false) ⇒ HerokuWhiz
Returns a new instance of HerokuWhiz.
38 39 40 41 42 43 44 45 46 |
# File 'lib/heroku_whiz.rb', line 38 def initialize(dir: '.', template: 'rack', appname: 'myapp', verbose: true, debug: false) @dir, @template, @appname, @verbose = dir, template, appname, verbose @app_path = File.join(@dir, @appname) end |
Instance Method Details
#app_url ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/heroku_whiz.rb', line 48 def app_url() app = `heroku config`.lines.first.split[1] s = "https://#{app}.herokuapp.com/" Clipboard.copy s puts 'app URL copied to clipboard.' return s end |
#create ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/heroku_whiz.rb', line 60 def create() case @template.to_sym when :rack create_rack() else return puts 'template not recognised!' end # build `bundle install` sleep 1 end |
#deploy ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/heroku_whiz.rb', line 100 def deploy() `git init` sleep 0.5 `git add .` sleep 0.5 `git commit -m 'pure rack app'` sleep 0.5 #`heroku create #{@appname}` # the above statement was commented out because there's a # high probability the appname you have chosen has already been taken # e.g. hello2 => hello2.herokuapp.com `heroku create` sleep 2 r = `git push heroku master` end |
#local_run ⇒ Object
124 125 126 |
# File 'lib/heroku_whiz.rb', line 124 def local_run() `bundle exec rackup -p 9292 config.ru &` end |
#local_testrun ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/heroku_whiz.rb', line 128 def local_testrun() r = IO.popen( "bundle exec rackup -p 9292 config.ru" ) puts 'r: ' + r.inspect if @debug sleep 2 s = URI.open('http://127.0.0.1:9292').read sleep 1 Process.kill('QUIT', r.pid) puts 'SUCCESS! Ready to deploy' if s == "Hello World!\n" end |
#wipe_clean(setup = :local) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/heroku_whiz.rb', line 75 def wipe_clean(setup=:local) return unless File.exists? @app_path # remove the app files # %w(Gemfile config.ru Gemfile.lock).each do |file| puts 'removing file ' + file if @debug rm File.join(@app_path, file) sleep 0.5 end rm_rf File.join(@app_path, '.git') rmdir File.join(@app_path, '.git') rmdir @app_path return unless setup == :both app = `heroku config`.lines.first.split[1] `heroku apps:destroy --confirm #{app}` end |