lib/ey-deploy/deploy_hook.rb in ey-deploy-0.3.1 vs lib/ey-deploy/deploy_hook.rb in ey-deploy-0.3.2

- old
+ new

@@ -22,10 +22,11 @@ end class CallbackContext def initialize(hook_runner, config) @hook_runner, @configuration = hook_runner, config + @node = node end def method_missing(meth, *args, &blk) if @configuration.respond_to?(meth) @configuration.send(meth, *args, &blk) @@ -42,9 +43,37 @@ system(@hook_runner.prepare_run(cmd)) end def sudo(cmd) system(@hook_runner.prepare_sudo(cmd)) + end + + # convenience functions for running on certain instance types + def on_app_master(&blk) on_roles(%w[solo app_master], &blk) end + def on_app_servers(&blk) on_roles(%w[solo app_master app], &blk) end + def on_db_master(&blk) on_roles(%w[solo db_master], &blk) end + def on_db_slaves(&blk) on_roles(%w[db_slave], &blk) end + def on_db_servers(&blk) on_roles(%w[solo db_master db_slave], &blk) end + def on_app_servers_and_utilities(&blk) on_roles(%w[solo app_master app util], &blk) end + + def on_utilities(*names, &blk) + names.flatten! + on_roles(%w[util]) do + blk.call if names.empty? || names.include?(current_name) + end + end + + private + def on_roles(desired_roles) + yield if desired_roles.include?(current_role.to_s) + end + + def current_role + node[:instance_role] + end + + def current_name + node[:name] end end end end