class Capistrano::Configuration::HostFilter

Public Class Methods

new(values) click to toggle source
# File lib/capistrano/configuration/host_filter.rb, line 4
def initialize(values)
  av = Array(values).dup
  av.map! { |v| (v.is_a?(String) && v =~ /^(?<name>[-A-Za-z0-9.]+)(,\g<name>)*$/) ? v.split(",") : v }
  av.flatten!
  @rex = regex_matcher(av)
end

Public Instance Methods

filter(servers) click to toggle source
# File lib/capistrano/configuration/host_filter.rb, line 11
def filter(servers)
  Array(servers).select { |s| @rex.match s.to_s }
end

Private Instance Methods

regex_matcher(values) click to toggle source
# File lib/capistrano/configuration/host_filter.rb, line 17
def regex_matcher(values)
  values.map! do |v|
    case v
    when Regexp then v
    else
      vs = v.to_s
      vs =~ /^[-A-Za-z0-9.]+$/ ? vs : Regexp.new(vs)
    end
  end
  Regexp.union values
end