Class: EY::Serverside::DeployHook
- Defined in:
- lib/engineyard-serverside/deploy_hook.rb
Defined Under Namespace
Classes: CallbackContext
Instance Method Summary collapse
- #call ⇒ Object
- #callback_context ⇒ Object
- #display_hook_error(exception, code, hook_path) ⇒ Object
- #eval_hook(code) ⇒ Object
- #hook_path ⇒ Object
-
#initialize(config, shell, hook_name) ⇒ DeployHook
constructor
A new instance of DeployHook.
- #syntax_error(file) ⇒ Object
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
#call ⇒ Object
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_context ⇒ Object
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_path ⇒ Object
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 |