Module: ShopifyCLI::Theme::Filter::PathMatcher
- Included in:
- IgnoreFilter, IncludeFilter
- Defined in:
- lib/shopify_cli/theme/filter/path_matcher.rb
Instance Method Summary collapse
- #as_glob(pattern) ⇒ Object
- #as_regex(pattern) ⇒ Object
- #glob_match?(glob, path) ⇒ Boolean
- #regex?(pattern) ⇒ Boolean
- #regex_match?(regex, path) ⇒ Boolean
Instance Method Details
#as_glob(pattern) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/shopify_cli/theme/filter/path_matcher.rb', line 25 def as_glob(pattern) # if specifying a directory, match everything below it pattern += "*" if pattern.end_with?("/") # The pattern will be scoped to root directory, so it should match anything # within that space pattern.prepend("*") unless pattern.start_with?("*") pattern end |
#as_regex(pattern) ⇒ Object
21 22 23 |
# File 'lib/shopify_cli/theme/filter/path_matcher.rb', line 21 def as_regex(pattern) Regexp.new(pattern.gsub(%r{^\/|\/$}, "")) end |
#glob_match?(glob, path) ⇒ Boolean
13 14 15 |
# File 'lib/shopify_cli/theme/filter/path_matcher.rb', line 13 def glob_match?(glob, path) !!::File.fnmatch?(glob, path) end |
#regex?(pattern) ⇒ Boolean
17 18 19 |
# File 'lib/shopify_cli/theme/filter/path_matcher.rb', line 17 def regex?(pattern) pattern.start_with?("/") && pattern.end_with?("/") end |
#regex_match?(regex, path) ⇒ Boolean
7 8 9 10 11 |
# File 'lib/shopify_cli/theme/filter/path_matcher.rb', line 7 def regex_match?(regex, path) regex.match?(path) rescue StandardError false end |