Class: HerokuApp

Inherits:
Rails::Generators::AppGenerator
  • Object
show all
Defined in:
lib/pah/templates/heroku.rb

Constant Summary collapse

DEFAULT_ADDONS =
%w(heroku-postgresql logentries sendgrid rollbar newrelic
librato)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ HerokuApp

Returns a new instance of HerokuApp.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/pah/templates/heroku.rb', line 7

def initialize(config)
  @config = config
  @name = Pah.configuration.heroku[:name]
  @description = description

  add_secret_token
  add_timezone_config
  add_addons
  add_librato_source
  add_heroku_git_remote
  check_canonical_domain
  check_collaborators
  schedule_backup
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



5
6
7
# File 'lib/pah/templates/heroku.rb', line 5

def config
  @config
end

#descriptionObject (readonly)

Returns the value of attribute description.



5
6
7
# File 'lib/pah/templates/heroku.rb', line 5

def description
  @description
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/pah/templates/heroku.rb', line 5

def name
  @name
end

Instance Method Details

#add_addonsObject



22
23
24
# File 'lib/pah/templates/heroku.rb', line 22

def add_addons
  DEFAULT_ADDONS.each { |addon| add_heroku_addon(addon) }
end

#add_canonical_domain(domain) ⇒ Object



41
42
43
# File 'lib/pah/templates/heroku.rb', line 41

def add_canonical_domain(domain)
  run "heroku domains:add #{domain} --app #{name}"
end

#add_collaborator(email) ⇒ Object



45
46
47
# File 'lib/pah/templates/heroku.rb', line 45

def add_collaborator(email)
  run "heroku sharing:add #{email} --app #{name}"
end

#add_heroku_addon(addon) ⇒ Object



36
37
38
39
# File 'lib/pah/templates/heroku.rb', line 36

def add_heroku_addon(addon)
  say "Adding heroku addon [#{addon}] to '#{name}'.".green
  run "heroku addons:create #{addon} --app #{name}"
end

#add_heroku_git_remoteObject



31
32
33
34
# File 'lib/pah/templates/heroku.rb', line 31

def add_heroku_git_remote
  say "Adding Heroku git remote for deploy to '#{name}'.".green
  run "git remote add heroku [email protected]:#{name}.git"
end

#add_librato_sourceObject



54
55
56
57
# File 'lib/pah/templates/heroku.rb', line 54

def add_librato_source
  say 'Configuring LIBRATO_SOURCE environment variable on Heroku'.green
  run "heroku config:set LIBRATO_SOURCE=#{name} --app #{name}"
end

#add_secret_tokenObject



26
27
28
29
# File 'lib/pah/templates/heroku.rb', line 26

def add_secret_token
  say "Creating SECRET_KEY_BASE for Heroku '#{name}.herokuapp.com'".green
  run "heroku config:set SECRET_KEY_BASE=#{SecureRandom.hex(60)} --app #{name}"
end

#add_timezone_configObject



49
50
51
52
# File 'lib/pah/templates/heroku.rb', line 49

def add_timezone_config
  say 'Adding timezone config on Heroku'.green
  run "heroku config:set TZ=America/Sao_Paulo --app #{name}"
end

#openObject



63
64
65
66
67
# File 'lib/pah/templates/heroku.rb', line 63

def open
  say 'Pushing application to heroku...'.green
  run 'git push heroku master'
  run "heroku open --app #{name}"
end

#schedule_backupObject



59
60
61
# File 'lib/pah/templates/heroku.rb', line 59

def schedule_backup
  run "heroku pg:backups schedule DATABASE_URL --at '02:00 America/Sao_Paulo' --app #{name}"
end