Class: EY::Serverside::DeployHook

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

Defined Under Namespace

Classes: CallbackContext

Instance Method Summary collapse

Constructor Details

#initialize(config, shell, hook_name) ⇒ DeployHook

Returns a new instance of DeployHook.



6
7
8
# File 'lib/engineyard-serverside/deploy_hook.rb', line 6

def initialize(config, shell, hook_name)
  @config, @shell, @hook_name = config, shell, hook_name
end

Instance Method Details

#callObject



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/engineyard-serverside/deploy_hook.rb', line 18

def call
  if hook_path.exist?
    Dir.chdir(@config.paths.active_release.to_s) do
      if desc = syntax_error(hook_path)
        hook_name = hook_path.basename
        abort "*** [Error] Invalid Ruby syntax in hook: #{hook_name} ***\n*** #{desc.chomp} ***"
      else
        eval_hook(hook_path.read)
      end
    end
  end
end

#callback_contextObject



14
15
16
# File 'lib/engineyard-serverside/deploy_hook.rb', line 14

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

#display_hook_error(exception, code, hook_path) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'lib/engineyard-serverside/deploy_hook.rb', line 38

def display_hook_error(exception, code, hook_path)
  @shell.fatal <<-ERROR
Exception raised in deploy hook #{hook_path}.

#{exception.class}: #{exception.to_s}

Please fix this error before retrying.
  ERROR
end

#eval_hook(code) ⇒ Object



31
32
33
34
35
36
# File 'lib/engineyard-serverside/deploy_hook.rb', line 31

def eval_hook(code)
  callback_context.instance_eval(code)
rescue Exception => exception
  display_hook_error(exception, code, hook_path)
  raise exception
end

#hook_pathObject



10
11
12
# File 'lib/engineyard-serverside/deploy_hook.rb', line 10

def hook_path
  @config.paths.deploy_hook(@hook_name)
end

#syntax_error(file) ⇒ Object



48
49
50
51
# File 'lib/engineyard-serverside/deploy_hook.rb', line 48

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