Sha256: 89cf5acd9b48c32560e7c72e6e83fc8110b78f04cde45a0845cf61019e0fa7f3

Contents?: true

Size: 687 Bytes

Versions: 1

Compression:

Stored size: 687 Bytes

Contents

module Capistrano
  class Configuration
    class HostFilter
      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

      def filter(servers)
        Array(servers).select { |s| @rex.match s.to_s }
      end

      private

      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
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
capistrano-3.5.0 lib/capistrano/configuration/host_filter.rb