Class: Maguro::Heroku

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(builder, app_name, organization) ⇒ Heroku

Returns a new instance of Heroku.



6
7
8
9
10
11
12
# File 'lib/maguro/heroku.rb', line 6

def initialize(builder, app_name, organization)
  @builder = builder
  @app_name = app_name.gsub(/[_ ]/,'-')
  @organization = organization
  @production_name = "#{@organization}-#{@app_name}"
  @staging_name = "#{@organization}-#{@app_name}-staging"
end

Instance Attribute Details

#app_nameObject (readonly)

Returns the value of attribute app_name.



4
5
6
# File 'lib/maguro/heroku.rb', line 4

def app_name
  @app_name
end

#builderObject (readonly)

Returns the value of attribute builder.



4
5
6
# File 'lib/maguro/heroku.rb', line 4

def builder
  @builder
end

#organizationObject (readonly)

Returns the value of attribute organization.



4
5
6
# File 'lib/maguro/heroku.rb', line 4

def organization
  @organization
end

#production_nameObject (readonly)

Returns the value of attribute production_name.



4
5
6
# File 'lib/maguro/heroku.rb', line 4

def production_name
  @production_name
end

#staging_nameObject (readonly)

Returns the value of attribute staging_name.



4
5
6
# File 'lib/maguro/heroku.rb', line 4

def staging_name
  @staging_name
end

Instance Method Details

#add_database(app_name) ⇒ Object



19
20
21
# File 'lib/maguro/heroku.rb', line 19

def add_database(app_name)
  builder.run "heroku addons:add heroku-postgresql --app #{app_name}"
end

#add_pg_backup(app_name, length = "month") ⇒ Object

addons.heroku.com/pgbackups length can be “week” or “month”



25
26
27
# File 'lib/maguro/heroku.rb', line 25

def add_pg_backup(app_name, length="month")
  builder.run "heroku addons:add pgbackups:auto-#{length} --app #{app_name}"
end

#createObject



29
30
31
32
33
34
35
36
37
38
# File 'lib/maguro/heroku.rb', line 29

def create
  create_app(staging_name, "staging")
  create_app(production_name, "production")

  add_database(staging_name)
  add_database(production_name)

  add_pg_backup(staging_name, "week")
  add_pg_backup(production_name)
end

#create_app(app_name, remote_name) ⇒ Object



14
15
16
# File 'lib/maguro/heroku.rb', line 14

def create_app(app_name, remote_name)
  builder.run "heroku apps:create #{app_name} --remote #{remote_name}"
end

#pushObject



40
41
42
43
# File 'lib/maguro/heroku.rb', line 40

def push
  builder.git push: "production master:master"
  builder.git push: "staging master:master"
end