class Makitzo::World::Query
Query
enables selection of a subset of hosts based on name/role
Attributes
hosts[R]
roles[R]
Public Class Methods
all()
click to toggle source
Returns a Query
which will match all hosts
# File lib/makitzo/world/query.rb, line 11 def self.all new end
new()
click to toggle source
# File lib/makitzo/world/query.rb, line 17 def initialize @roles, @hosts = StringArray.new, StringArray.new end
Public Instance Methods
empty?()
click to toggle source
# File lib/makitzo/world/query.rb, line 21 def empty? @roles.empty? && @hosts.empty? end
exec(config)
click to toggle source
# File lib/makitzo/world/query.rb, line 35 def exec(config) if !empty? hosts, all_hosts = [], config.hosts if @roles.length > 0 hosts |= all_hosts.select { |host| (@roles & (host.roles.map { |r| r.name })).any? } end if @hosts.length > 0 host_patterns = @hosts.map { |h| Regexp.new('^' + h.gsub('.', '\\.').gsub('*', '.*?') + '$') } hosts |= all_hosts.select { |host| host_patterns.any? { |hp| host.name =~ hp } } end else hosts = config.hosts end hosts end
includes?(host)
click to toggle source
# File lib/makitzo/world/query.rb, line 31 def includes?(host) empty? || @hosts.include?(host.to_s) || (host.roles.any? { |r| @roles.include?(r.to_s) }) end
merge!(query)
click to toggle source
# File lib/makitzo/world/query.rb, line 25 def merge!(query) @roles |= query.roles @hosts |= query.hosts self end