Class: ShopifyCLI::Theme::IncludeFilter

Inherits:
Object
  • Object
show all
Includes:
Filter::PathMatcher
Defined in:
lib/shopify_cli/theme/include_filter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Filter::PathMatcher

#as_glob, #as_regex, #glob_match?, #regex?, #regex_match?

Constructor Details

#initialize(root, patterns = []) ⇒ IncludeFilter

Returns a new instance of IncludeFilter.



12
13
14
15
16
17
18
19
20
# File 'lib/shopify_cli/theme/include_filter.rb', line 12

def initialize(root, patterns = [])
  @root = Pathname.new(root)
  @patterns = patterns.nil? ? [] : patterns.compact.reject(&:empty?)

  regexes, globs = patterns_to_regexes_and_globs(@patterns)

  @regexes = regexes
  @globs = globs
end

Instance Attribute Details

#globsObject (readonly)

Returns the value of attribute globs.



10
11
12
# File 'lib/shopify_cli/theme/include_filter.rb', line 10

def globs
  @globs
end

#regexesObject (readonly)

Returns the value of attribute regexes.



10
11
12
# File 'lib/shopify_cli/theme/include_filter.rb', line 10

def regexes
  @regexes
end

Instance Method Details

#match?(path) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/shopify_cli/theme/include_filter.rb', line 22

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

  path = path.to_s
  return true if path.empty?

  path = @root.join(path).to_s

  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