File: matcher.rb

package info (click to toggle)
ruby-guard 2.18.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,344 kB
  • sloc: ruby: 9,256; makefile: 6
file content (33 lines) | stat: -rw-r--r-- 749 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
module Guard
  class Watcher
    class Pattern
      class Matcher
        attr_reader :matcher

        def initialize(obj)
          @matcher = obj
        end

        # Compare with other matcher
        # @param other [Guard::Watcher::Pattern::Matcher]
        #   other matcher for comparing
        # @return [true, false] equal or not
        def ==(other)
          matcher == other.matcher
        end

        def match(string_or_pathname)
          @matcher.match(normalized(string_or_pathname))
        end

        private

        def normalized(string_or_pathname)
          path = Pathname.new(string_or_pathname).cleanpath
          return path.to_s if @matcher.is_a?(Regexp)
          path
        end
      end
    end
  end
end