Sha256: aa38a21172e7ad748d1e3bea79941209ccbc903a8255176574ceb11f170a275e

Contents?: true

Size: 680 Bytes

Versions: 3

Compression:

Stored size: 680 Bytes

Contents

module Capistrano
  class Configuration
    class RoleFilter
      def initialize(values)
        av = Array(values).dup
        av.map! { |v| v.is_a?(String) ? v.split(",") : v }
        av.flatten!
        @rex = regex_matcher(av)
      end

      def filter(servers)
        Array(servers).select { |s| s.is_a?(String) ? false : s.roles.any? { |r| @rex.match r } }
      end

      private

      def regex_matcher(values)
        values.map! do |v|
          case v
          when Regexp then v
          else
            vs = v.to_s
            vs =~ %r{^/(.+)/$} ? Regexp.new($1) : /^#{vs}$/
          end
        end
        Regexp.union values
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
capistrano-3.6.1 lib/capistrano/configuration/role_filter.rb
capistrano-3.6.0 lib/capistrano/configuration/role_filter.rb
capistrano-3.5.0 lib/capistrano/configuration/role_filter.rb