Class: EY::Serverside::DeployHook::CallbackContext

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Shell::Helpers

#debug, #info, #logged_system, #verbose?, #warning

Constructor Details

#initialize(config, shell, hook_path) ⇒ CallbackContext

Returns a new instance of CallbackContext.



58
59
60
61
62
63
64
# File 'lib/engineyard-serverside/deploy_hook.rb', line 58

def initialize(config, shell, hook_path)
  @configuration = config
  @configuration.set_framework_envs
  @shell = shell
  @node = node
  @hook_path = hook_path
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &blk) ⇒ Object



74
75
76
77
78
79
80
# File 'lib/engineyard-serverside/deploy_hook.rb', line 74

def method_missing(meth, *args, &blk)
  if @configuration.respond_to?(meth)
    @configuration.send(meth, *args, &blk)
  else
    super
  end
end

Instance Attribute Details

#shellObject (readonly)

Returns the value of attribute shell.



56
57
58
# File 'lib/engineyard-serverside/deploy_hook.rb', line 56

def shell
  @shell
end

Instance Method Details

#configObject



66
67
68
# File 'lib/engineyard-serverside/deploy_hook.rb', line 66

def config
  @configuration
end

#inspectObject



70
71
72
# File 'lib/engineyard-serverside/deploy_hook.rb', line 70

def inspect
  "#<DeployHook::CallbackContext #{hook_path.inspect}>"
end

#on_app_master(&blk) ⇒ Object

convenience functions for running on certain instance types



103
# File 'lib/engineyard-serverside/deploy_hook.rb', line 103

def on_app_master(&blk)                 on_roles(%w[solo app_master],          &blk) end

#on_app_servers(&blk) ⇒ Object



104
# File 'lib/engineyard-serverside/deploy_hook.rb', line 104

def on_app_servers(&blk)                on_roles(%w[solo app_master app],      &blk) end

#on_app_servers_and_utilities(&blk) ⇒ Object



105
# File 'lib/engineyard-serverside/deploy_hook.rb', line 105

def on_app_servers_and_utilities(&blk)  on_roles(%w[solo app_master app util], &blk) end

#on_utilities(*names, &blk) ⇒ Object



107
108
109
110
111
112
# File 'lib/engineyard-serverside/deploy_hook.rb', line 107

def on_utilities(*names, &blk)
  names.flatten!
  on_roles(%w[util]) do
    blk.call if names.empty? || names.include?(current_name)
  end
end

#respond_to?(*a) ⇒ Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/engineyard-serverside/deploy_hook.rb', line 82

def respond_to?(*a)
  @configuration.respond_to?(*a) || super
end

#run(cmd) ⇒ Object



86
87
88
# File 'lib/engineyard-serverside/deploy_hook.rb', line 86

def run(cmd)
  shell.logged_system(Escape.shell_command(["sh", "-l", "-c", cmd])).success?
end

#run!(cmd) ⇒ Object



90
91
92
# File 'lib/engineyard-serverside/deploy_hook.rb', line 90

def run!(cmd)
  run(cmd) or raise("run!: Command failed. #{cmd}")
end

#sudo(cmd) ⇒ Object



94
95
96
# File 'lib/engineyard-serverside/deploy_hook.rb', line 94

def sudo(cmd)
  shell.logged_system(Escape.shell_command(["sudo", "sh", "-l", "-c", cmd])).success?
end

#sudo!(cmd) ⇒ Object



98
99
100
# File 'lib/engineyard-serverside/deploy_hook.rb', line 98

def sudo!(cmd)
  sudo(cmd) or raise("sudo!: Command failed. #{cmd}")
end