Sha256: 88b91f11588d928ee0057f98683b42d4209eab261ea21910e17fba62b9bf7577

Contents?: true

Size: 809 Bytes

Versions: 3

Compression:

Stored size: 809 Bytes

Contents

# frozen_string_literal: true

require_relative "filter/path_matcher"

module ShopifyCLI
  module Theme
    class IncludeFilter
      include Filter::PathMatcher

      def initialize(pattern = nil)
        @pattern = pattern
      end

      def match?(path)
        return true unless present?(@pattern)

        if regex_pattern?
          regex_match?(regex_pattern, path)
        else
          glob_match?(glob_pattern, path)
        end
      end

      private

      def present?(pattern)
        !pattern.nil? && !pattern.empty?
      end

      def regex_pattern?
        @is_regex_pattern ||= regex?(@pattern)
      end

      def regex_pattern
        @regex_pattern ||= as_regex(@pattern)
      end

      def glob_pattern
        @glob_pattern ||= as_glob(@pattern)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
shopify-cli-2.10.2 lib/shopify_cli/theme/include_filter.rb
shopify-cli-2.10.1 lib/shopify_cli/theme/include_filter.rb
shopify-cli-2.10.0 lib/shopify_cli/theme/include_filter.rb