class HerokuSan::Stage

Attributes

heroku[R]
name[R]
options[R]

Public Class Methods

new(stage, options = {}) click to toggle source
# File lib/heroku_san/stage.rb, line 12
def initialize(stage, options = {})
  @name = stage
  @options = options
  @heroku = options.delete(:api) || HerokuSan::API.new
end

Public Instance Methods

==(other) click to toggle source
# File lib/heroku_san/stage.rb, line 18
def ==(other)
  other.name == name && other.options == options
end
addons() click to toggle source
# File lib/heroku_san/stage.rb, line 42
def addons
  (@options['addons'] ||= []).flatten
end
app() click to toggle source
# File lib/heroku_san/stage.rb, line 22
def app
  @options['app'] or raise MissingApp, "#{name}: is missing the app: configuration value. I don't know what to access on Heroku."
end
config() click to toggle source
# File lib/heroku_san/stage.rb, line 38
def config
  @options['config'] ||= {}
end
create() click to toggle source
# File lib/heroku_san/stage.rb, line 83
def create
  params = {
      'name' => @options['app'],
      'stack' => @options['stack']
  }
  response = heroku.post_app(params)
  response.body['name']
end
deploy(commit = nil, force = nil) click to toggle source
# File lib/heroku_san/stage.rb, line 60
def deploy(commit = nil, force = nil)
  strategy = @options['deploy'].new(self, commit, force)
  strategy.deploy
end
install_addons() click to toggle source
# File lib/heroku_san/stage.rb, line 113
def install_addons
  addons_to_install = addons - installed_addons.map{|a|a['name']}
  addons_to_install.each do |addon|
    heroku.post_addon(app, addon)
  end
  installed_addons
end
installed_addons() click to toggle source
# File lib/heroku_san/stage.rb, line 109
def installed_addons
  heroku.get_addons(app).body
end
logs(tail = false) click to toggle source
# File lib/heroku_san/stage.rb, line 125
def logs(tail = false)
  heroku.sh app, 'logs', (tail ? '--tail' : nil)
end
long_config() click to toggle source
# File lib/heroku_san/stage.rb, line 100
def long_config
  heroku.get_config_vars(app).body
end
maintenance(action = nil) { || ... } click to toggle source
# File lib/heroku_san/stage.rb, line 69
def maintenance(action = nil)
  if block_given?
    heroku.post_app_maintenance(app, '1')
    begin
      yield
    ensure
      heroku.post_app_maintenance(app, '0')
    end
  else
    raise ArgumentError, "Action #{action.inspect} must be one of (:on, :off)", caller if ![:on, :off].include?(action)
    heroku.post_app_maintenance(app, {:on => '1', :off => '0'}[action])
  end
end
migrate() click to toggle source
# File lib/heroku_san/stage.rb, line 55
def migrate
  run('rake db:migrate')
  restart
end
push(sha = nil, force = false) click to toggle source
# File lib/heroku_san/stage.rb, line 50
def push(sha = nil, force = false)
  sha ||= git_parsed_tag(tag)
  git_push(sha, repo, force ? %w[--force] : [])
end
push_config(options = nil) click to toggle source
# File lib/heroku_san/stage.rb, line 104
def push_config(options = nil)
  params = (options || config)
  heroku.put_config_vars(app, params).body
end
rake(*args) click to toggle source
# File lib/heroku_san/stage.rb, line 65
def rake(*args)
  raise HerokuSan::Deprecated.new("use Stage#run instead")
end
repo() click to toggle source
# File lib/heroku_san/stage.rb, line 26
def repo
  @options['repo'] ||= "git@heroku.com:#{app}.git"
end
restart() click to toggle source
# File lib/heroku_san/stage.rb, line 121
def restart
  "restarted" if heroku.post_ps_restart(app).body == 'ok'
end
revision() click to toggle source
# File lib/heroku_san/stage.rb, line 129
def revision
  git_named_rev(git_revision(repo))
end
run(command, args = nil) click to toggle source
# File lib/heroku_san/stage.rb, line 46
def run(command, args = nil)
  heroku.sh app, "run", command, *args
end
sharing_add(email) click to toggle source
# File lib/heroku_san/stage.rb, line 92
def sharing_add(email) # DEPREC?
  raise HerokuSan::Deprecated
end
sharing_remove(email) click to toggle source
# File lib/heroku_san/stage.rb, line 96
def sharing_remove(email) # DEPREC?
  raise HerokuSan::Deprecated
end
stack() click to toggle source
# File lib/heroku_san/stage.rb, line 30
def stack
  @options['stack'] ||= heroku.get_stack(app).body.detect{|stack| stack['current']}['name']
end
tag() click to toggle source
# File lib/heroku_san/stage.rb, line 34
def tag
  @options['tag']
end