Class: ConradFiler::WatchJob
- Inherits:
-
Object
- Object
- ConradFiler::WatchJob
- Defined in:
- lib/conrad_filer/watch_job.rb
Overview
A watch job describes directories to monitor and includes a bitmask describing which actions to monitor
Instance Method Summary collapse
- #add_rule(id_type, rule) ⇒ Object
- #bitmask ⇒ Object
- #id_types ⇒ Object
-
#initialize(db, a_hash) ⇒ WatchJob
constructor
A new instance of WatchJob.
- #is_valid? ⇒ Boolean
- #pathname ⇒ Object
- #prepare_inotify_thread ⇒ Object
- #process_event(notify_event, path) ⇒ Object
- #recursive? ⇒ Boolean
- #start_inotify_loop ⇒ Object
- #start_inotify_thread ⇒ Object
Constructor Details
#initialize(db, a_hash) ⇒ WatchJob
Returns a new instance of WatchJob.
9 10 11 12 13 14 |
# File 'lib/conrad_filer/watch_job.rb', line 9 def initialize(db, a_hash) @db_rec = a_hash @bitmask = Inotify::InotifyBitmask.new(@db_rec['BITMASK']) @rules = Hash.new {Array.new} @inotify_thread = Inotify::InotifyThread.new end |
Instance Method Details
#add_rule(id_type, rule) ⇒ Object
20 21 22 |
# File 'lib/conrad_filer/watch_job.rb', line 20 def add_rule(id_type, rule) @rules[id_type] = @rules[id_type] << rule end |
#bitmask ⇒ Object
32 33 34 |
# File 'lib/conrad_filer/watch_job.rb', line 32 def bitmask @bitmask.bitmask end |
#id_types ⇒ Object
16 17 18 |
# File 'lib/conrad_filer/watch_job.rb', line 16 def id_types @rules.keys end |
#is_valid? ⇒ Boolean
36 37 38 |
# File 'lib/conrad_filer/watch_job.rb', line 36 def is_valid? @rules.size > 0 end |
#pathname ⇒ Object
28 29 30 |
# File 'lib/conrad_filer/watch_job.rb', line 28 def pathname @db_rec['PATHNAME'] end |
#prepare_inotify_thread ⇒ Object
40 41 42 43 |
# File 'lib/conrad_filer/watch_job.rb', line 40 def prepare_inotify_thread @inotify_thread.add_watch(self.pathname, self.bitmask, self.recursive?) @inotify_thread.register_event(self.bitmask, &(self.method(:process_event))) end |
#process_event(notify_event, path) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/conrad_filer/watch_job.rb', line 55 def process_event(notify_event, path) bitmask = Inotify::InotifyBitmask.new(notify_event.mask) puts "[ConradWatchJob::process_event] '#{path}/#{notify_event.name}' #{bitmask.as_array_of_symbols}" @rules.each_pair do |id_type, rules_for_id_type| if id_type.matches_pathname?(File.join(path,notify_event.name.to_s)) rules_for_id_type.each do |rule| rule.on_watch_event(self, id_type, notify_event, path) end end end end |
#recursive? ⇒ Boolean
24 25 26 |
# File 'lib/conrad_filer/watch_job.rb', line 24 def recursive? @db_rec['RECURSIVE'][0,1].upcase == "T" end |
#start_inotify_loop ⇒ Object
50 51 52 53 |
# File 'lib/conrad_filer/watch_job.rb', line 50 def start_inotify_loop self.prepare_inotify_thread @inotify_thread.start_loop end |
#start_inotify_thread ⇒ Object
45 46 47 48 |
# File 'lib/conrad_filer/watch_job.rb', line 45 def start_inotify_thread self.prepare_inotify_thread @inotify_thread.start_thread end |