Module: Loom::Pattern::ExpandingReference::Matcher::GlobMatcher

Defined in:
lib/loom/pattern/expanding_reference.rb

Constant Summary collapse

MATCH_P =
/(\*)$/

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.handles_pattern?(p) ⇒ Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/loom/pattern/expanding_reference.rb', line 71

def self.handles_pattern?(p)
  p.match? MATCH_P
end

Instance Method Details

#match?(your_pattern) ⇒ Boolean

Returns:

  • (Boolean)


75
76
77
78
79
80
81
82
83
84
# File 'lib/loom/pattern/expanding_reference.rb', line 75

def match?(your_pattern)
  # TODO: This can be made RE2 compliant later.
  unless GlobMatcher.handles_pattern?(@my_slug)
    raise 'WTF? invalid pattern, must end in "*": %s' % @my_slug
  end

  prefix = @my_slug.to_s.gsub(MATCH_P, "")
  Loom.log.debug2(self) { "GlobMatcher+match?+ #{@my_slug} #{your_pattern}, prefix: #{prefix}"}
  your_pattern.to_s.start_with? prefix
end