Class: WhizBase

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

Direct Known Subclasses

SinatraWhiz

Instance Method Summary collapse

Constructor Details

#initialize(app_path, debug: false) ⇒ WhizBase

Returns a new instance of WhizBase.



42
43
44
45
46
# File 'lib/heroku_whiz.rb', line 42

def initialize(app_path, debug: false)

  @app_path, debug = app_path, debug

end

Instance Method Details

#createObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/heroku_whiz.rb', line 48

def create()

  config = %q(
run lambda {|env|
[200, {'Content-Type'=>'text/plain'}, StringIO.new("Hello World!\n")]
})

  gemfile = %q(
source 'https://rubygems.org'
gem 'rack'
gem 'puma'
)

  # Procfile: see https://devcenter.heroku.com/articles/procfile
  #           for more info
  procfile = 'web: bundle exec rackup config.ru -p $PORT'

  create_basefiles(config, gemfile, procfile)
end

#deployObject



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

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_runObject



118
119
120
121
122
123
124
125
# File 'lib/heroku_whiz.rb', line 118

def local_run()

  #`heroku local &`
  # attempted to use heroku local but couldn't automatically kill the
  # process directly

  `bundle exec rackup -p 9292 config.ru &`
end

#local_testrunObject



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/heroku_whiz.rb', line 127

def local_testrun()

  #r = IO.popen("heroku local")
  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

currently only removes a file directory if there are no user created files



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/heroku_whiz.rb', line 70

def wipe_clean(setup=:local)

  return unless File.exists? @app_path

  # remove the app files
  #
  %w(Gemfile config.ru Procfile 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

  `heroku apps:destroy --confirm #{heroku_app()}`

end