Class: EY::Serverside::Task

Inherits:
Object show all
Defined in:
lib/engineyard-serverside/task.rb

Direct Known Subclasses

DeployBase, DeployHook

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(conf) ⇒ Task

Returns a new instance of Task.



8
9
10
11
# File 'lib/engineyard-serverside/task.rb', line 8

def initialize(conf)
  @config = conf
  @roles = :all
end

Instance Attribute Details

#configObject (readonly) Also known as: c

Returns the value of attribute config.



5
6
7
# File 'lib/engineyard-serverside/task.rb', line 5

def config
  @config
end

Instance Method Details

#require_custom_tasksObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/engineyard-serverside/task.rb', line 13

def require_custom_tasks
  deploy_file = ["config/eydeploy.rb", "eydeploy.rb"].map do |short_file|
    File.join(c.repository_cache, short_file)
  end.detect do |file|
    File.exist?(file)
  end

  if deploy_file
    puts "~> Loading deployment task overrides from #{deploy_file}"
    instance_eval(File.read(deploy_file))
    true
  else
    false
  end
end

#roles(*task_roles) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/engineyard-serverside/task.rb', line 29

def roles(*task_roles)
  raise "Roles must be passed a block" unless block_given?

  begin
    @roles = task_roles
    yield
  ensure
    @roles = :all
  end
end

#run(cmd, &blk) ⇒ Object

Returns true if the command is successful, raises EY::Serverside::RemoteFailure with a list of failures otherwise.



43
44
45
# File 'lib/engineyard-serverside/task.rb', line 43

def run(cmd, &blk)
  run_on_roles(cmd, &blk)
end

#sudo(cmd, &blk) ⇒ Object



47
48
49
# File 'lib/engineyard-serverside/task.rb', line 47

def sudo(cmd, &blk)
  run_on_roles(cmd, %w[sudo sh -l -c], &blk)
end