Class: SwitchTower::Actor::Task
- Inherits:
-
Object
- Object
- SwitchTower::Actor::Task
- Defined in:
- lib/switchtower/actor.rb
Overview
Represents the definition of a single task.
Instance Attribute Summary collapse
-
#actor ⇒ Object
readonly
:nodoc:.
-
#name ⇒ Object
readonly
:nodoc:.
-
#options ⇒ Object
readonly
:nodoc:.
Instance Method Summary collapse
-
#initialize(name, actor, options) ⇒ Task
constructor
A new instance of Task.
-
#servers ⇒ Object
Returns the list of servers (not connections to servers) that are the target of this task.
Constructor Details
#initialize(name, actor, options) ⇒ Task
Returns a new instance of Task.
74 75 76 77 |
# File 'lib/switchtower/actor.rb', line 74 def initialize(name, actor, ) @name, @actor, @options = name, actor, @servers = nil end |
Instance Attribute Details
#actor ⇒ Object (readonly)
:nodoc:
72 73 74 |
# File 'lib/switchtower/actor.rb', line 72 def actor @actor end |
#name ⇒ Object (readonly)
:nodoc:
72 73 74 |
# File 'lib/switchtower/actor.rb', line 72 def name @name end |
#options ⇒ Object (readonly)
:nodoc:
72 73 74 |
# File 'lib/switchtower/actor.rb', line 72 def @options end |
Instance Method Details
#servers ⇒ Object
Returns the list of servers (not connections to servers) that are the target of this task.
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/switchtower/actor.rb', line 81 def servers unless @servers roles = [*(@options[:roles] || actor.configuration.roles.keys)]. map { |name| actor.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.[key] != only[key] end false end end end @servers = roles.map { |role| role.host }.uniq end @servers end |