Class: Rascut::FileObserver
- Inherits:
-
Object
- Object
- Rascut::FileObserver
- Defined in:
- lib/rascut/file_observer.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
{ :interval => 1, :ignore_files => [], :ignore_dirs => [/\/.svn/], :logger => Logger.new(STDOUT), :dir_counter => 5, :ext => nil }
- MSWIN32 =
!!RUBY_PLATFORM.include?('mswin32')
Instance Attribute Summary collapse
-
#dirs ⇒ Object
readonly
Returns the value of attribute dirs.
-
#files ⇒ Object
readonly
Returns the value of attribute files.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #add_update_handler(handler) ⇒ Object
-
#initialize(files, options) ⇒ FileObserver
constructor
A new instance of FileObserver.
- #logger ⇒ Object
- #observe(files) ⇒ Object
- #remove_update_handler(handler) ⇒ Object
- #run ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(files, options) ⇒ FileObserver
Returns a new instance of FileObserver.
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/rascut/file_observer.rb', line 18 def initialize(files, ) @files = {} @dirs = {} @options = DEFAULT_OPTIONS.merge @update_handlers = [] @th = nil if [:update_handler] add_update_handler .delete(:update_handler) end observe files end |
Instance Attribute Details
#dirs ⇒ Object (readonly)
Returns the value of attribute dirs.
32 33 34 |
# File 'lib/rascut/file_observer.rb', line 32 def dirs @dirs end |
#files ⇒ Object (readonly)
Returns the value of attribute files.
32 33 34 |
# File 'lib/rascut/file_observer.rb', line 32 def files @files end |
#options ⇒ Object
Returns the value of attribute options.
31 32 33 |
# File 'lib/rascut/file_observer.rb', line 31 def @options end |
Instance Method Details
#add_update_handler(handler) ⇒ Object
51 52 53 54 55 |
# File 'lib/rascut/file_observer.rb', line 51 def add_update_handler(handler) unless @update_handlers.include? handler @update_handlers << handler end end |
#logger ⇒ Object
34 35 36 |
# File 'lib/rascut/file_observer.rb', line 34 def logger [:logger] end |
#observe(files) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/rascut/file_observer.rb', line 65 def observe(files) Array(files).each do |file| file = Pathname.new(file) if file.directory? dir_observe file else next if @options[:ignore_files].include?(file.realpath) file_observe file end end end |
#remove_update_handler(handler) ⇒ Object
57 58 59 |
# File 'lib/rascut/file_observer.rb', line 57 def remove_update_handler(handler) @update_handlers.delete_if {|h| h == handler} end |
#run ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/rascut/file_observer.rb', line 38 def run if @th @th.run else @th = Thread.start do loop do update_check sleep @options[:interval] end end end end |
#stop ⇒ Object
61 62 63 |
# File 'lib/rascut/file_observer.rb', line 61 def stop @th.kill end |