Class | Capistrano::Role |
In: |
lib/capistrano/role.rb
lib/capistrano/role.rb |
Parent: | Object |
# File lib/capistrano/role.rb, line 5 5: def initialize(*list) 6: @static_servers = [] 7: @dynamic_servers = [] 8: push(*list) 9: end
# File lib/capistrano/role.rb, line 5 5: def initialize(*list) 6: @static_servers = [] 7: @dynamic_servers = [] 8: push(*list) 9: end
Turns a list, or something resembling a list, into a properly-formatted ServerDefinition list. Keep an eye on this one — it‘s entirely too magical for its own good. In particular, if ServerDefinition ever inherits from Array, this will break.
# File lib/capistrano/role.rb, line 83 83: def self.wrap_list (*list) 84: options = list.last.is_a?(Hash) ? list.pop : {} 85: if list.length == 1 86: if list.first.nil? 87: return [] 88: elsif list.first.is_a?(Array) 89: list = list.first 90: end 91: end 92: options.merge! list.pop if list.last.is_a?(Hash) 93: list.map do |item| 94: self.wrap_server item, options 95: end 96: end
Turns a list, or something resembling a list, into a properly-formatted ServerDefinition list. Keep an eye on this one — it‘s entirely too magical for its own good. In particular, if ServerDefinition ever inherits from Array, this will break.
# File lib/capistrano/role.rb, line 83 83: def self.wrap_list (*list) 84: options = list.last.is_a?(Hash) ? list.pop : {} 85: if list.length == 1 86: if list.first.nil? 87: return [] 88: elsif list.first.is_a?(Array) 89: list = list.first 90: end 91: end 92: options.merge! list.pop if list.last.is_a?(Hash) 93: list.map do |item| 94: self.wrap_server item, options 95: end 96: end
Wraps a string in a ServerDefinition, if it isn‘t already. This and wrap_list should probably go in ServerDefinition in some form.
# File lib/capistrano/role.rb, line 75 75: def self.wrap_server (item, options) 76: item.is_a?(ServerDefinition) ? item : ServerDefinition.new(item, options) 77: end
Wraps a string in a ServerDefinition, if it isn‘t already. This and wrap_list should probably go in ServerDefinition in some form.
# File lib/capistrano/role.rb, line 75 75: def self.wrap_server (item, options) 76: item.is_a?(ServerDefinition) ? item : ServerDefinition.new(item, options) 77: end
# File lib/capistrano/role.rb, line 36 36: def clear 37: @dynamic_servers.clear 38: @static_servers.clear 39: end
# File lib/capistrano/role.rb, line 36 36: def clear 37: @dynamic_servers.clear 38: @static_servers.clear 39: end
# File lib/capistrano/role.rb, line 15 15: def push(*list) 16: options = list.last.is_a?(Hash) ? list.pop : {} 17: list.each do |item| 18: if item.respond_to?(:call) 19: @dynamic_servers << DynamicServerList.new(item, options) 20: else 21: @static_servers << self.class.wrap_server(item, options) 22: end 23: end 24: end
# File lib/capistrano/role.rb, line 15 15: def push(*list) 16: options = list.last.is_a?(Hash) ? list.pop : {} 17: list.each do |item| 18: if item.respond_to?(:call) 19: @dynamic_servers << DynamicServerList.new(item, options) 20: else 21: @static_servers << self.class.wrap_server(item, options) 22: end 23: end 24: end
# File lib/capistrano/role.rb, line 27 27: def servers 28: @static_servers + dynamic_servers 29: end
# File lib/capistrano/role.rb, line 27 27: def servers 28: @static_servers + dynamic_servers 29: end
Attribute reader for the cached results of executing the blocks in turn
# File lib/capistrano/role.rb, line 69 69: def dynamic_servers 70: @dynamic_servers.inject([]) { |list, item| list.concat item } 71: end