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.



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

def initialize(config, shell, hook_path)
  @configuration = config
  @configuration.set_framework_envs
  @shell = shell
  @node = config.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



92
93
94
95
96
97
98
99
# File 'lib/engineyard-serverside/deploy_hook.rb', line 92

def method_missing(meth, *args, &blk)
  if @configuration.respond_to?(meth)
    shell.warning "Use of `#{meth}` (via method_missing) is deprecated in favor of `config.#{meth}` for improved error messages and compatibility.\n\tin #{hook_path}"
    @configuration.send(meth, *args, &blk)
  else
    super
  end
end

Instance Attribute Details

#hook_pathObject (readonly)

Returns the value of attribute hook_path.



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

def hook_path
  @hook_path
end

#shellObject (readonly)

Returns the value of attribute shell.



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

def shell
  @shell
end

Instance Method Details

#configObject



84
85
86
# File 'lib/engineyard-serverside/deploy_hook.rb', line 84

def config
  @configuration
end

#inspectObject



88
89
90
# File 'lib/engineyard-serverside/deploy_hook.rb', line 88

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

#on_app_master(&blk) ⇒ Object

convenience functions for running on certain instance types



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

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

#on_app_servers(&blk) ⇒ Object



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

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

#on_app_servers_and_utilities(&blk) ⇒ Object



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

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

#on_utilities(*names, &blk) ⇒ Object



126
127
128
129
130
131
# File 'lib/engineyard-serverside/deploy_hook.rb', line 126

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

#respond_to?(*a) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#run(cmd) ⇒ Object



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

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

#run!(cmd) ⇒ Object



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

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

#sudo(cmd) ⇒ Object



113
114
115
# File 'lib/engineyard-serverside/deploy_hook.rb', line 113

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

#sudo!(cmd) ⇒ Object



117
118
119
# File 'lib/engineyard-serverside/deploy_hook.rb', line 117

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