Class Rascut::FileObserver
In: lib/rascut/file_observer.rb
Parent: Object

Methods

Constants

DEFAULT_OPTIONS = { :interval => 1, :ignore_files => [], :ignore_dirs => [/\/.svn/], :logger => Logger.new(STDOUT), :dir_counter => 5, :ext => nil
MSWIN32 = !!RUBY_PLATFORM.include?('mswin32')

Attributes

dirs  [R] 
files  [R] 
options  [RW] 

Public Class methods

[Source]

    # File lib/rascut/file_observer.rb, line 18
18:     def initialize(files, options)
19:       @files = {}
20:       @dirs = {}
21:       @options = DEFAULT_OPTIONS.merge options
22:       @update_handlers = []
23:       @th = nil
24: 
25:       if options[:update_handler]
26:         add_update_handler options.delete(:update_handler)
27:       end
28: 
29:       observe files
30:     end

Public Instance methods

[Source]

    # File lib/rascut/file_observer.rb, line 51
51:     def add_update_handler(handler)
52:       unless @update_handlers.include? handler
53:         @update_handlers << handler
54:       end
55:     end

[Source]

    # File lib/rascut/file_observer.rb, line 34
34:     def logger
35:       options[:logger]
36:     end

[Source]

    # File lib/rascut/file_observer.rb, line 65
65:     def observe(files)
66:       Array(files).each do |file|
67:         file = Pathname.new(file)
68:         if file.directory?
69:           dir_observe file
70:         else
71:           next if @options[:ignore_files].include?(file.realpath)
72: 
73:           file_observe file
74:         end
75:       end
76:     end

[Source]

    # File lib/rascut/file_observer.rb, line 57
57:     def remove_update_handler(handler)
58:       @update_handlers.delete_if {|h| h == handler}
59:     end

[Source]

    # File lib/rascut/file_observer.rb, line 38
38:     def run
39:       if @th
40:         @th.run
41:       else
42:         @th = Thread.start do
43:           loop do
44:             update_check
45:             sleep @options[:interval]
46:           end
47:         end
48:       end
49:     end

[Source]

    # File lib/rascut/file_observer.rb, line 61
61:     def stop
62:       @th.kill
63:     end

[Validate]