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
-
#name ⇒ Object
readonly
:nodoc:.
-
#options ⇒ Object
readonly
:nodoc:.
Instance Method Summary collapse
-
#initialize(name, options) ⇒ Task
constructor
A new instance of Task.
-
#servers(configuration) ⇒ Object
Returns the list of servers (not connections to servers) that are the target of this task.
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, ) @name, @options = name, @servers = nil end |
Instance Attribute Details
#name ⇒ Object (readonly)
:nodoc:
65 66 67 |
# File 'lib/switchtower/actor.rb', line 65 def name @name end |
#options ⇒ Object (readonly)
:nodoc:
65 66 67 |
# File 'lib/switchtower/actor.rb', line 65 def @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.[key] != only[key] end false end end end @servers = roles.map { |role| role.host }.uniq end @servers end |