class Hat::Deployment

Attributes

cap[RW]
configuration[RW]
stage_name[RW]

Public Class Methods

new(stage_name, file_name = nil) click to toggle source
# File lib/hat/deployment.rb, line 14
def initialize stage_name, file_name = nil
  self.configuration = Konf.new(file_name || 'deploy.yml')
  self.stage_name = stage_name || "staging"
  self.cap = Capistrano::Application.new
end

Public Instance Methods

run() click to toggle source
# File lib/hat/deployment.rb, line 20
def run
  recipes.download
  run_with_bundler(recipes.gemfile) do
    stage.set_defaults(configuration['defaults'])
    stage.define_task(recipes)
    cap.invoke stage.name   # http://capistranorb.com/documentation/advanced-features/capistrano-pure-ruby/
    cap.invoke 'deploy'
  end
end

Private Instance Methods

recipes() click to toggle source
# File lib/hat/deployment.rb, line 32
def recipes
  @recipes ||= Recipes.new(configuration['recipes'] || {})
end
run_with_bundler(gemfile) { || ... } click to toggle source
# File lib/hat/deployment.rb, line 40
def run_with_bundler(gemfile)
  if File.exists?(gemfile)
    Bundler.with_clean_env do
      ENV['BUNDLE_GEMFILE'] = gemfile
      Bundler.setup
      yield
    end
  else
    yield
  end
end
stage() click to toggle source
# File lib/hat/deployment.rb, line 36
def stage
  @stage ||= Stage.new(stage_name, configuration['stages'][stage_name] || {}, recipes.list)
end