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 87 87: def self.wrap_list (*list) 88: options = list.last.is_a?(Hash) ? list.pop : {} 89: if list.length == 1 90: if list.first.nil? 91: return [] 92: elsif list.first.is_a?(Array) 93: list = list.first 94: end 95: end 96: options.merge! list.pop if list.last.is_a?(Hash) 97: list.map do |item| 98: self.wrap_server item, options 99: end 100: 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 87 87: def self.wrap_list (*list) 88: options = list.last.is_a?(Hash) ? list.pop : {} 89: if list.length == 1 90: if list.first.nil? 91: return [] 92: elsif list.first.is_a?(Array) 93: list = list.first 94: end 95: end 96: options.merge! list.pop if list.last.is_a?(Hash) 97: list.map do |item| 98: self.wrap_server item, options 99: end 100: 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 79 79: def self.wrap_server (item, options) 80: item.is_a?(ServerDefinition) ? item : ServerDefinition.new(item, options) 81: 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 79 79: def self.wrap_server (item, options) 80: item.is_a?(ServerDefinition) ? item : ServerDefinition.new(item, options) 81: 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 41 41: def include?(server) 42: servers.include?(server) 43: end
# File lib/capistrano/role.rb, line 41 41: def include?(server) 42: servers.include?(server) 43: 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 73 73: def dynamic_servers 74: @dynamic_servers.inject([]) { |list, item| list.concat item } 75: end