class Kitchen::PlatformFilter
A wrapper on Regexp and strings to mix them in platform filters.
This should handle backward compatibility in most cases were platform are matched against a filters array using Array.include?
This wrapper does not work if filters arrays are converted to Set.
@author Baptiste Courtois <b.courtois@criteo.com>
Constants
- REGEXP_LIKE_PATTERN
Pattern used to determine whether a filter should be handled as a Regexp
Attributes
@return [Regexp] value of this filter
Public Class Methods
Converts platform filters into an array of PlatformFilter
handling both strings and Regexp. A string “looks-like” a regexp if it starts by / and end by / + Regexp options i or x
@return [Array] filters with regexp-like string converted to PlatformRegexpFilter
# File lib/kitchen/platform_filter.rb, line 35 def self.convert(filters) ::Kernel.Array(filters).map do |filter| if (match = filter.match(REGEXP_LIKE_PATTERN)) options = match["options"].include?("i") ? ::Regexp::IGNORECASE : 0 options |= ::Regexp::EXTENDED if match["options"].include?("x") filter = ::Regexp.new(match["pattern"], options) end new(filter) end end
Constructs a new filter.
@param [Regexp,String] value of the filter
# File lib/kitchen/platform_filter.rb, line 52 def initialize(value) raise ::ArgumentError, "PlatformFilter#new requires value to be a String or a Regexp" unless value.is_a?(::Regexp) || value.is_a?(::String) @value = value end
Public Instance Methods
Override of the equality operator to check whether the wrapped Regexp match the given object.
@param [Object] other object to compare to @return [Boolean] whether the objects are equal or the wrapped Regexp matches the given string or symbol
# File lib/kitchen/platform_filter.rb, line 62 def ==(other) if @value.is_a?(::Regexp) && (other.is_a?(::String) || other.is_a?(::Symbol)) @value =~ other else other == @value end end