File: watch.rb

package info (click to toggle)
ruby-compass 1.0.3~dfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 8,184 kB
  • ctags: 1,789
  • sloc: ruby: 12,904; makefile: 100; perl: 43; xml: 14; sh: 4
file content (38 lines) | stat: -rw-r--r-- 913 bytes parent folder | download | duplicates (2)
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
34
35
36
37
38
module Compass
  module Configuration
    class Watch
      attr_reader :callback
      attr_reader :glob
      attr_reader :full_glob

      def initialize(glob, &block)
        unless block
          raise ArgumentError, "A Block must be supplied in order to be watched"
        end
        @callback = block
        unless glob
          raise ArgumentErrorn, "A glob must be supplied in order to be watched"
        end
        @glob = glob

        if Pathname.new(glob).absolute?
          @full_glob = glob
        else
          @full_glob = File.join(Compass.configuration.project_path, glob)
        end
      end

      def run_callback(base, relative, action)
        callback.call(base, relative, action)
      end

      def run_once_per_changeset?
        false
      end

      def match?(changed_path)
        File.fnmatch(full_glob, changed_path, File::FNM_PATHNAME)
      end
    end
  end
end