Class: Shining::Heroku

Inherits:
Object
  • Object
show all
Extended by:
FileMethods
Defined in:
lib/shining/heroku.rb

Defined Under Namespace

Classes: FailCreatingApp

Instance Method Summary collapse

Methods included from FileMethods

basename, change_dir, copy, delete!, dir?, dirname, erb, expand, extname, file?, json, move, name_and_extension, new_dir, new_file, read_file

Constructor Details

#initialize(preso) ⇒ Heroku

Returns a new instance of Heroku.

Raises:

  • (RuntimeError)


11
12
13
14
15
# File 'lib/shining/heroku.rb', line 11

def initialize preso
  raise RuntimeError, 'Git is either not installed or not in your PATH. Check and try again.' if `which git`.empty?
  @preso  = preso
  @client = ::Heroku::Command.run_internal 'auth:client', []
end

Instance Method Details

#create_app(name = preso.name) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/shining/heroku.rb', line 17

def create_app name = preso.name
  Shining.say "\tCreating #{name} on Heroku..."
  begin
    @client.create name
    change_dir @preso.path
    `git remote add heroku git@#{@client.host}:#{name}.git`
  rescue RestClient::RequestFailed => error
    case error.http_code
    when 422
      Shining.error "\tApparently #{name} already exists on Heroku. Try again with a different name."
    else
      Shining.error "\tAn error ocurred when creating #{name}. Maybe try again in a moment?"
    end
    raise FailCreatingApp
  end
end

#deploy(name) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/shining/heroku.rb', line 34

def deploy name
  change_dir @preso.path
  Shining.say "Creating Git repository on #{@preso.path}" do `git init` end unless git_repo?
  Shining.say "Updating presentation's contents" do
    `git add .`
    system "git commit -a -m 'heroku deploy'"
  end
  create_app(name) unless heroku_app?
  Shining.say "Pushing to Heroku" do
    system "git push heroku master"
  end
  Shining.say "Done! Visit http://#{name}.heroku.com to browse your presentation."
  Shining.say "If you're updating, make sure you do a hard refresh (shift + refresh on most modern browsers)."
end