Sha256: d5827b6f0efb45b13bfa151826c1af76946791396762cc4a00d26e67eed970af
Contents?: true
Size: 1.4 KB
Versions: 3
Compression:
Stored size: 1.4 KB
Contents
# frozen_string_literal: true require_relative "filter/path_matcher" module ShopifyCLI module Theme class IncludeFilter include Filter::PathMatcher attr_reader :globs, :regexes def initialize(patterns = []) @patterns = patterns.nil? ? [] : patterns.compact.reject(&:empty?) regexes, globs = patterns_to_regexes_and_globs(@patterns) @regexes = regexes @globs = globs end def match?(path) return true unless present?(@patterns) path = path.to_s return true if path.empty? regexes.each do |regex| return true if regex_match?(regex, path) end globs.each do |glob| return true if glob_match?(glob, path) end false end private def present?(patterns) !patterns.nil? && !patterns.empty? end # Take in string patterns and convert them to either # regex patterns or glob patterns so that they are handled in an expected manner. def patterns_to_regexes_and_globs(patterns) new_regexes = [] new_globs = [] patterns .map(&:strip) .each do |pattern| if regex?(pattern) new_regexes << as_regex(pattern) else new_globs << as_glob(pattern) end end [new_regexes, new_globs] end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
shopify-cli-2.11.2 | lib/shopify_cli/theme/include_filter.rb |
shopify-cli-2.11.1 | lib/shopify_cli/theme/include_filter.rb |
shopify-cli-2.11.0 | lib/shopify_cli/theme/include_filter.rb |