Class: AvoDeploy::Task::Task

Inherits:
Object
  • Object
show all
Defined in:
lib/avodeploy/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.



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

def block
  @block
end

#descObject

Returns the value of attribute desc.



27
28
29
# File 'lib/avodeploy/task/task.rb', line 27

def desc
  @desc
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#remote_exceptObject

Returns the value of attribute remote_except.



29
30
31
# File 'lib/avodeploy/task/task.rb', line 29

def remote_except
  @remote_except
end

#remote_onlyObject

Returns the value of attribute remote_only.



28
29
30
# File 'lib/avodeploy/task/task.rb', line 28

def remote_only
  @remote_only
end

#scopeObject

Returns the value of attribute scope.



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

def scope
  @scope
end

#visibilityObject

Returns the value of attribute visibility.



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

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



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/avodeploy/task/task.rb', line 37

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

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

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

  instance
end

Instance Method Details

#invoke(env, options = {}) ⇒ mixed

Runs the code of a task

Parameters:

  • env (TaskExecutionEnvironment)

    the environment to invoke the task in

  • options (Hash) (defaults to: {})

    a hash contining additional options

Returns:

  • (mixed)

    result of the code block



75
76
77
78
79
80
81
82
83
# File 'lib/avodeploy/task/task.rb', line 75

def invoke(env, options = {})
  raise ArgumentError 'env must be a valid TaskExecutionEnvironment' unless env.kind_of?(TaskExecutionEnvironment)

  avo = AvoDeploy::Deployment.instance

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

  env.instance_eval(&@block)
end