Class: EY::DeployHook

Inherits:
Task show all
Defined in:
lib/ey-deploy/deploy_hook.rb

Defined Under Namespace

Classes: CallbackContext

Constant Summary

Constants included from Dataflow

Dataflow::UnificationError, Dataflow::VERSION

Instance Attribute Summary

Attributes inherited from Task

#config

Instance Method Summary collapse

Methods inherited from Task

#require_custom_tasks, #roles, #sudo

Methods included from Dataflow

#barrier, #by_need, #flow, included, #local, #need_later, #unify

Constructor Details

#initialize(options) ⇒ DeployHook

Returns a new instance of DeployHook.



3
4
5
# File 'lib/ey-deploy/deploy_hook.rb', line 3

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

Instance Method Details

#callback_contextObject



7
8
9
# File 'lib/ey-deploy/deploy_hook.rb', line 7

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

#run(hook) ⇒ Object



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

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



26
27
28
29
# File 'lib/ey-deploy/deploy_hook.rb', line 26

def syntax_error(file)
  valid = Kernel.system("ruby -c #{file} 2>/tmp/ey_invalid_deploy_hook | grep 'Syntax OK' --quiet")
  File.new("/tmp/ey_invalid_deploy_hook").gets unless valid
end