Class: EY::Serverside::Callbacks::Executor::Ruby::Context

Inherits:
Object
  • Object
show all
Includes:
Shell::Helpers
Defined in:
lib/engineyard-serverside/callbacks/executor/ruby/context.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) ⇒ Context

Returns a new instance of Context.


14
15
16
17
18
19
20
# File 'lib/engineyard-serverside/callbacks/executor/ruby/context.rb', line 14

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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


30
31
32
33
34
35
36
37
# File 'lib/engineyard-serverside/callbacks/executor/ruby/context.rb', line 30

def method_missing(meth, *args, &blk)
  if config.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}"
    config.send(meth, *args, &blk)
  else
    super
  end
end

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration


12
13
14
# File 'lib/engineyard-serverside/callbacks/executor/ruby/context.rb', line 12

def configuration
  @configuration
end

#hookObject (readonly)

Returns the value of attribute hook


12
13
14
# File 'lib/engineyard-serverside/callbacks/executor/ruby/context.rb', line 12

def hook
  @hook
end

#shellObject (readonly)

Returns the value of attribute shell


12
13
14
# File 'lib/engineyard-serverside/callbacks/executor/ruby/context.rb', line 12

def shell
  @shell
end

Instance Method Details

#configObject


22
23
24
# File 'lib/engineyard-serverside/callbacks/executor/ruby/context.rb', line 22

def config
  @configuration
end

#inspectObject


26
27
28
# File 'lib/engineyard-serverside/callbacks/executor/ruby/context.rb', line 26

def inspect
  "#<Callbacks::Executor::Ruby::Context #{hook.path.inspect}>"
end

#on_app_master(&blk) ⇒ Object

convenience functions for running on certain instance types


60
# File 'lib/engineyard-serverside/callbacks/executor/ruby/context.rb', line 60

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

#on_app_servers(&blk) ⇒ Object


61
# File 'lib/engineyard-serverside/callbacks/executor/ruby/context.rb', line 61

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

#on_app_servers_and_utilities(&blk) ⇒ Object


62
# File 'lib/engineyard-serverside/callbacks/executor/ruby/context.rb', line 62

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

#on_utilities(*names, &blk) ⇒ Object


64
65
66
67
68
69
# File 'lib/engineyard-serverside/callbacks/executor/ruby/context.rb', line 64

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)

39
40
41
# File 'lib/engineyard-serverside/callbacks/executor/ruby/context.rb', line 39

def respond_to?(*a)
  config.respond_to?(*a) || super
end

#run(cmd) ⇒ Object


43
44
45
# File 'lib/engineyard-serverside/callbacks/executor/ruby/context.rb', line 43

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

#run!(cmd) ⇒ Object


47
48
49
# File 'lib/engineyard-serverside/callbacks/executor/ruby/context.rb', line 47

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

#sudo(cmd) ⇒ Object


51
52
53
# File 'lib/engineyard-serverside/callbacks/executor/ruby/context.rb', line 51

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

#sudo!(cmd) ⇒ Object


55
56
57
# File 'lib/engineyard-serverside/callbacks/executor/ruby/context.rb', line 55

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