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

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 50
50:     def add_update_handler(handler)
51:       unless @update_handlers.include? handler
52:         @update_handlers << handler
53:       end
54:     end

[Source]

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

[Source]

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

[Source]

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

[Source]

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

[Source]

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

[Validate]