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.36.0 lib/shopify_cli/theme/filter/path_matcher.rb
shopify-cli-2.35.0 lib/shopify_cli/theme/filter/path_matcher.rb
shopify-cli-2.34.0 lib/shopify_cli/theme/filter/path_matcher.rb
shopify-cli-2.33.1 lib/shopify_cli/theme/filter/path_matcher.rb
shopify-cli-2.33.0 lib/shopify_cli/theme/filter/path_matcher.rb
shopify-cli-2.32.1 lib/shopify_cli/theme/filter/path_matcher.rb
shopify-cli-2.32.0 lib/shopify_cli/theme/filter/path_matcher.rb
shopify-cli-2.31.0 lib/shopify_cli/theme/filter/path_matcher.rb
shopify-cli-2.30.0 lib/shopify_cli/theme/filter/path_matcher.rb
shopify-cli-2.29.0 lib/shopify_cli/theme/filter/path_matcher.rb
shopify-cli-2.28.0 lib/shopify_cli/theme/filter/path_matcher.rb
shopify-cli-2.27.0 lib/shopify_cli/theme/filter/path_matcher.rb
shopify-cli-2.26.0 lib/shopify_cli/theme/filter/path_matcher.rb
shopify-cli-2.25.0 lib/shopify_cli/theme/filter/path_matcher.rb
shopify-cli-2.24.0 lib/shopify_cli/theme/filter/path_matcher.rb
shopify-cli-2.23.0 lib/shopify_cli/theme/filter/path_matcher.rb
shopify-cli-2.22.0 lib/shopify_cli/theme/filter/path_matcher.rb
shopify-cli-2.21.0 lib/shopify_cli/theme/filter/path_matcher.rb
shopify-cli-2.20.1 lib/shopify_cli/theme/filter/path_matcher.rb
shopify-cli-2.20.0 lib/shopify_cli/theme/filter/path_matcher.rb