Class: Bigrig::GoMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/bigrig/go_matcher.rb

Constant Summary collapse

ESCAPES =
['.', '(', ')']
REPLACES =
{
  /^\/?/ => '',
  /^/ => '^',
  /$/ => '/',
  '?' => '[^/]',
  '+' => '\\\\+',
  '*' => '[^/]+'
}

Instance Method Summary collapse

Constructor Details

#initialize(glob) ⇒ GoMatcher

Returns a new instance of GoMatcher.



17
18
19
20
21
# File 'lib/bigrig/go_matcher.rb', line 17

def initialize(glob)
  ESCAPES.each { |e| glob.gsub! e, "\\#{e}" }
  REPLACES.each { |k, v| glob.gsub! k, v }
  @regex = %r{#{glob}} # rubocop:disable Style/RegexpLiteral
end

Instance Method Details

#matches?(path) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/bigrig/go_matcher.rb', line 23

def matches?(path)
  @regex.match("#{path}/") != nil
end