Class: SwitchTower::Actor::Task

Inherits:
Object
  • Object
show all
Defined in:
lib/switchtower/actor.rb

Overview

Represents the definition of a single task.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options) ⇒ Task

Returns a new instance of Task.



67
68
69
70
# File 'lib/switchtower/actor.rb', line 67

def initialize(name, options)
  @name, @options = name, options
  @servers = nil
end

Instance Attribute Details

#nameObject (readonly)

:nodoc:



65
66
67
# File 'lib/switchtower/actor.rb', line 65

def name
  @name
end

#optionsObject (readonly)

:nodoc:



65
66
67
# File 'lib/switchtower/actor.rb', line 65

def options
  @options
end

Instance Method Details

#servers(configuration) ⇒ Object

Returns the list of servers (not connections to servers) that are the target of this task.



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/switchtower/actor.rb', line 74

def servers(configuration)
  unless @servers
    roles = [*(@options[:roles] || configuration.roles.keys)].map { |name| configuration.roles[name] or raise ArgumentError, "task #{self.name.inspect} references non-existant role #{name.inspect}" }.flatten
    only  = @options[:only] || {}

    unless only.empty?
      roles = roles.delete_if do |role|
        catch(:done) do
          only.keys.each do |key|
            throw(:done, true) if role.options[key] != only[key]
          end
          false
        end
      end
    end

    @servers = roles.map { |role| role.host }.uniq
  end

  @servers
end