Sha256: e59a5c3e49023234b5be231fe1af43c7b39599315188477a85f8d4829604da48

Contents?: true

Size: 902 Bytes

Versions: 42

Compression:

Stored size: 902 Bytes

Contents

# frozen_string_literal: true

module ShopifyCLI
  module Theme
    module Filter
      module PathMatcher
        def regex_match?(regex, path)
          regex.match?(path)
        rescue StandardError
          false
        end

        def glob_match?(glob, path)
          !!::File.fnmatch?(glob, path)
        end

        def regex?(pattern)
          pattern.start_with?("/") && pattern.end_with?("/")
        end

        def as_regex(pattern)
          Regexp.new(pattern.gsub(%r{^\/|\/$}, ""))
        end

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

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
shopify-cli-2.19.0 lib/shopify_cli/theme/filter/path_matcher.rb
shopify-cli-2.18.1 lib/shopify_cli/theme/filter/path_matcher.rb
shopify-cli-2.18.0 lib/shopify_cli/theme/filter/path_matcher.rb
shopify-cli-2.17.0 lib/shopify_cli/theme/filter/path_matcher.rb
shopify-cli-2.16.1 lib/shopify_cli/theme/filter/path_matcher.rb
shopify-cli-2.16.0 lib/shopify_cli/theme/filter/path_matcher.rb
shopify-cli-2.15.6 lib/shopify_cli/theme/filter/path_matcher.rb
shopify-cli-2.15.5 lib/shopify_cli/theme/filter/path_matcher.rb
shopify-cli-2.15.4 lib/shopify_cli/theme/filter/path_matcher.rb
shopify-cli-2.15.3 lib/shopify_cli/theme/filter/path_matcher.rb
shopify-cli-2.15.2 lib/shopify_cli/theme/filter/path_matcher.rb
shopify-cli-2.15.1 lib/shopify_cli/theme/filter/path_matcher.rb
shopify-cli-2.15.0 lib/shopify_cli/theme/filter/path_matcher.rb
shopify-cli-2.14.0 lib/shopify_cli/theme/filter/path_matcher.rb
shopify-cli-2.13.0 lib/shopify_cli/theme/filter/path_matcher.rb
shopify-cli-2.12.0 lib/shopify_cli/theme/filter/path_matcher.rb
shopify-cli-2.11.2 lib/shopify_cli/theme/filter/path_matcher.rb
shopify-cli-2.11.1 lib/shopify_cli/theme/filter/path_matcher.rb
shopify-cli-2.11.0 lib/shopify_cli/theme/filter/path_matcher.rb
shopify-cli-2.10.2 lib/shopify_cli/theme/filter/path_matcher.rb