Class: EY::Serverside::DeployHook

Inherits:
Task show all
Defined in:
lib/engineyard-serverside/deploy_hook.rb

Defined Under Namespace

Classes: CallbackContext

Instance Attribute Summary

Attributes inherited from Task

#config

Instance Method Summary collapse

Methods inherited from Task

#require_custom_tasks, #roles, #sudo

Constructor Details

#initialize(options) ⇒ DeployHook

Returns a new instance of DeployHook.



4
5
6
# File 'lib/engineyard-serverside/deploy_hook.rb', line 4

def initialize(options)
  super(EY::Serverside::Deploy::Configuration.new(options))
end

Instance Method Details

#callback_contextObject



8
9
10
# File 'lib/engineyard-serverside/deploy_hook.rb', line 8

def callback_context
  @context ||= CallbackContext.new(config)
end

#run(hook) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/engineyard-serverside/deploy_hook.rb', line 12

def run(hook)
  hook_path = "#{c.release_path}/deploy/#{hook}.rb"
  if File.exist?(hook_path)
    Dir.chdir(c.release_path) do
      puts "~> running deploy hook: deploy/#{hook}.rb"
      if desc = syntax_error(hook_path)
        hook_name = File.basename(hook_path)
        abort "*** [Error] Invalid Ruby syntax in hook: #{hook_name} ***\n*** #{desc.chomp} ***"
      else
        callback_context.instance_eval(IO.read(hook_path))
      end
    end
  end
end

#syntax_error(file) ⇒ Object



27
28
29
30
# File 'lib/engineyard-serverside/deploy_hook.rb', line 27

def syntax_error(file)
  output = `ruby -c #{file} 2>&1`
  output unless output =~ /Syntax OK/
end