Class: Avocado::Task

Inherits:
Object
  • Object
show all
Defined in:
lib/avocado/task/task.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#blockObject

Returns the value of attribute block.



25
26
27
# File 'lib/avocado/task/task.rb', line 25

def block
  @block
end

#descObject

Returns the value of attribute desc.



26
27
28
# File 'lib/avocado/task/task.rb', line 26

def desc
  @desc
end

#nameObject

Returns the value of attribute name.



22
23
24
# File 'lib/avocado/task/task.rb', line 22

def name
  @name
end

#scopeObject

Returns the value of attribute scope.



23
24
25
# File 'lib/avocado/task/task.rb', line 23

def scope
  @scope
end

#visibilityObject

Returns the value of attribute visibility.



24
25
26
# File 'lib/avocado/task/task.rb', line 24

def visibility
  @visibility
end

Class Method Details

.from_task_block(name, options, &block) ⇒ Task

Creates a new task from a task block in the deployment configuration process

Parameters:

  • name (Symbol)

    name of the task

  • options (Hash)

    command options

  • block (Block)

    code block of the task

Returns:

  • (Task)

    the task instance



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/avocado/task/task.rb', line 34

def self.from_task_block(name, options, &block)
  instance = self.new

  instance.name = name
  instance.block = block

  instance.scope = :local

  if options.has_key?(:scope) && options[:scope] == :remote
    instance.scope = :remote
  end

  instance.visibility = :public

  if options.has_key?(:visibility) && options[:visibility] == :private
    instance.visibility = :private
  end

  if options.has_key?(:desc)
    instance.desc = options[:desc]
  end

  instance
end

Instance Method Details

#invoke(env) ⇒ mixed

Runs the code of a task

Parameters:

Returns:

  • (mixed)

    result of the code block



63
64
65
66
67
68
69
70
71
# File 'lib/avocado/task/task.rb', line 63

def invoke(env)
  raise ArgumentError 'env must be a valid TaskExecutionEnvironment' unless env.kind_of?(Avocado::TaskExecutionEnvironment)

  avo = Avocado::Deployment.instance

  avo.log.debug "Running task #{@name}"

  env.instance_eval(&@block)
end

#pretty_printObject

Prettyprints a command using a table



74
75
76
77
78
79
80
81
# File 'lib/avocado/task/task.rb', line 74

def pretty_print
  puts Terminal::Table.new :title => 'Task overview', :rows => [
    ['Name', @name.to_s],
    ['Description', @desc.to_s],
    ['Scope', @scope.to_s],
    ['Visibility', @visibility.to_s],
  ]
end