Class: DirectoryWatcher::Configuration
- Inherits:
-
Object
- Object
- DirectoryWatcher::Configuration
- Defined in:
- lib/directory_watcher/configuration.rb
Overview
The top level configuration options used by DirectoryWatcher are used by many of the sub components for a variety of purposes. The Configuration represents all those options and other global like instances.
The top level DirectoryWatcher class allows the configs to be changed during execution, so all of the dependent classes need to be informed when their options have changed. This class allows that.
Instance Attribute Summary collapse
-
#collection_queue ⇒ Object
readonly
The Queue through which the Scanner will send data to the Collector.
-
#dir ⇒ Object
readonly
The directory to monitor for events.
-
#glob ⇒ Object
The glob of files to monitor.
-
#interval ⇒ Object
The interval at which to do a full scan using the
glob
to determine Events to send. -
#logger ⇒ Object
The logger through wich every one will log.
-
#notification_queue ⇒ Object
readonly
The Queue through which the Collector will send data to the Notifier.
-
#order_by ⇒ Object
When sorting you may pick if the order should be:.
-
#persist ⇒ Object
The filename to persist the state of the DirectoryWatcher too upon calling stop.
-
#pre_load ⇒ Object
readonly
pre_load says if an initial scan using the globs should be done to pre populate the state of the system before sending any events.
-
#scanner ⇒ Object
readonly
The back end scanner to use.
-
#sort_by ⇒ Object
The sorting method to use when emitting a set of Events after a Scan has happened.
-
#stable ⇒ Object
Controls the number of intervals a file must remain unchanged before it is considered “stable”.
Class Method Summary collapse
-
.default_options ⇒ Object
Return a Hash of all the default options.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Configuration
constructor
Create a new Configuration by blending the passed in items with the defaults.
-
#pre_load? ⇒ Boolean
Is pre_load set or not.
-
#scanner_class ⇒ Object
The class of the scanner.
Constructor Details
#initialize(options = {}) ⇒ Configuration
Create a new Configuration by blending the passed in items with the defaults
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/directory_watcher/configuration.rb', line 116 def initialize( = {} ) o = self.class..merge( ) @dir = o[:dir] @pre_load = o[:pre_load] @scanner = o[:scanner] @sort_by = o[:sort_by] @order_by = o[:order_by] # These have validation rules self.persist = o[:persist] self.interval = o[:interval] self.glob = o[:glob] self.stable = o[:stable] self.logger = o[:logger] @notification_queue = Queue.new @collection_queue = Queue.new end |
Instance Attribute Details
#collection_queue ⇒ Object (readonly)
The Queue through which the Scanner will send data to the Collector
87 88 89 |
# File 'lib/directory_watcher/configuration.rb', line 87 def collection_queue @collection_queue end |
#dir ⇒ Object (readonly)
The directory to monitor for events. The glob’s will be used in conjunction with this directory to find the full list of globs available.
13 14 15 |
# File 'lib/directory_watcher/configuration.rb', line 13 def dir @dir end |
#glob ⇒ Object
The glob of files to monitor. This is an Array of file matching globs be aware that changing the :glob value after watching has started has the potential to cause spurious events if the new globs do not match the old, files will appear to have been deleted.
The default is ‘*’
21 22 23 |
# File 'lib/directory_watcher/configuration.rb', line 21 def glob @glob end |
#interval ⇒ Object
The interval at which to do a full scan using the glob
to determine Events to send.
The default is 30.0 seconds
27 28 29 |
# File 'lib/directory_watcher/configuration.rb', line 27 def interval @interval end |
#logger ⇒ Object
The logger through wich every one will log
95 96 97 |
# File 'lib/directory_watcher/configuration.rb', line 95 def logger @logger end |
#notification_queue ⇒ Object (readonly)
The Queue through which the Collector will send data to the Notifier
91 92 93 |
# File 'lib/directory_watcher/configuration.rb', line 91 def notification_queue @notification_queue end |
#order_by ⇒ Object
When sorting you may pick if the order should be:
:ascending => The default, from lowest to highest
:descending => from highest to lowest.
83 84 85 |
# File 'lib/directory_watcher/configuration.rb', line 83 def order_by @order_by end |
#persist ⇒ Object
The filename to persist the state of the DirectoryWatcher too upon calling stop.
The default is nil, indicating that no state is to be persisted.
47 48 49 |
# File 'lib/directory_watcher/configuration.rb', line 47 def persist @persist end |
#pre_load ⇒ Object (readonly)
pre_load says if an initial scan using the globs should be done to pre populate the state of the system before sending any events.
The default is false
41 42 43 |
# File 'lib/directory_watcher/configuration.rb', line 41 def pre_load @pre_load end |
#scanner ⇒ Object (readonly)
The back end scanner to use. The available options are:
nil => Use the default, pure ruby Threaded scanner
:em => Use the EventMachine based scanner. This requires that the
'eventmachine' gem be installed.
:coolio => Use the Cool.io based scanner. This requires that the
'cool.io' gem be installed.
:rev => Use the Rev based scanner. This requires that the 'rev' gem be
installed.
The default is nil, indicating the pure ruby threaded scanner will be used. This option may not be changed once the DirectoryWatcher is allocated.
62 63 64 |
# File 'lib/directory_watcher/configuration.rb', line 62 def scanner @scanner end |
#sort_by ⇒ Object
The sorting method to use when emitting a set of Events after a Scan has happened. Since a Scan may produce a number of events, if those Events should be emitted in a particular order, use sort_by
to pick which field to sort the events, and order_by
to say if those events are to be emitted in :ascending or :descending order.
Available options:
:path => The default, they will be sorted by full pathname
:mtime => Last modified time. They will be sorted by their FileStat mtime
:size => The number of bytes in the file.
76 77 78 |
# File 'lib/directory_watcher/configuration.rb', line 76 def sort_by @sort_by end |
#stable ⇒ Object
Controls the number of intervals a file must remain unchanged before it is considered “stable”. When this condition is met, a stable event is generated for the file. If stable is set to nil
then stable events will not be generated.
The default is nil, indicating no stable events are to be emitted.
35 36 37 |
# File 'lib/directory_watcher/configuration.rb', line 35 def stable @stable end |
Class Method Details
.default_options ⇒ Object
Return a Hash of all the default options
99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/directory_watcher/configuration.rb', line 99 def self. { :dir => '.', :glob => '*', :interval => 30.0, :stable => nil, :pre_load => false, :persist => nil, :scanner => nil, :sort_by => :path, :order_by => :ascending, :logger => nil, } end |
Instance Method Details
#pre_load? ⇒ Boolean
Is pre_load set or not
137 138 139 |
# File 'lib/directory_watcher/configuration.rb', line 137 def pre_load? @pre_load end |
#scanner_class ⇒ Object
The class of the scanner
143 144 145 146 |
# File 'lib/directory_watcher/configuration.rb', line 143 def scanner_class class_name = scanner.to_s.capitalize + 'Scanner' DirectoryWatcher.const_get( class_name ) rescue DirectoryWatcher::Scanner end |