Class: INotify::INotify
- Inherits:
-
Object
- Object
- INotify::INotify
- Defined in:
- lib/vim_mate/plugins/inotify/lib/INotify.rb
Instance Method Summary collapse
- #close ⇒ Object
- #each_event ⇒ Object
- #ignore_dir(dir) ⇒ Object
- #ignore_dir_recursively(dir) ⇒ Object
-
#initialize ⇒ INotify
constructor
A new instance of INotify.
- #next_events ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
- #watch_dir(dir, option = IN_ALL_EVENTS) ⇒ Object
- #watch_dir_recursively(dir, option = IN_ALL_EVENTS) ⇒ Object
Constructor Details
#initialize ⇒ INotify
Returns a new instance of INotify.
124 125 126 127 128 |
# File 'lib/vim_mate/plugins/inotify/lib/INotify.rb', line 124 def initialize @wd_dir = Hash.new @dir_wd = Hash.new @io = IO.open(syscall(INOTIFY_INIT)) end |
Instance Method Details
#close ⇒ Object
130 131 132 |
# File 'lib/vim_mate/plugins/inotify/lib/INotify.rb', line 130 def close @io.close end |
#each_event ⇒ Object
177 178 179 |
# File 'lib/vim_mate/plugins/inotify/lib/INotify.rb', line 177 def each_event loop { next_events.each { |event| yield event } } end |
#ignore_dir(dir) ⇒ Object
147 148 149 |
# File 'lib/vim_mate/plugins/inotify/lib/INotify.rb', line 147 def ignore_dir (dir) syscall(INOTIFY_RM_WATCH, @io.fileno, @dir_wd[dir]) end |
#ignore_dir_recursively(dir) ⇒ Object
155 156 157 |
# File 'lib/vim_mate/plugins/inotify/lib/INotify.rb', line 155 def ignore_dir_recursively (dir) Find.find(dir) { |sub_dir| ignore_dir(sub_dir) if (File::directory?(sub_dir) == true) } end |
#next_events ⇒ Object
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/vim_mate/plugins/inotify/lib/INotify.rb', line 159 def next_events begin read_cnt = @io.read(16) wd, mask, , len = read_cnt.unpack('lLLL') read_cnt = @io.read(len) filename = read_cnt.unpack('Z*') end while (mask & IN_Q_OVERFLOW.value) != 0 events = Array.new AllMasks.each_value do |m| next if m.value == IN_ALL_EVENTS.value events.push Event.new(@wd_dir[wd].to_s, filename.to_s, m.name.to_s, ) if (m.value & mask) != 0 end return events end |
#start ⇒ Object
181 182 183 |
# File 'lib/vim_mate/plugins/inotify/lib/INotify.rb', line 181 def start @thread = Thread.new { loop { next_events.each { |event| yield event } } } end |
#stop ⇒ Object
185 186 187 |
# File 'lib/vim_mate/plugins/inotify/lib/INotify.rb', line 185 def stop @thread.exit end |
#watch_dir(dir, option = IN_ALL_EVENTS) ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/vim_mate/plugins/inotify/lib/INotify.rb', line 134 def watch_dir (dir, option = IN_ALL_EVENTS) wd = syscall(INOTIFY_ADD_WATCH, @io.fileno, dir, option.value) if wd >= 0 @dir_wd[dir] = wd @wd_dir[wd] = dir end return wd rescue Errno::EACCES => e STDERR.puts e. end |
#watch_dir_recursively(dir, option = IN_ALL_EVENTS) ⇒ Object
151 152 153 |
# File 'lib/vim_mate/plugins/inotify/lib/INotify.rb', line 151 def watch_dir_recursively (dir, option = IN_ALL_EVENTS) Find.find(dir) { |sub_dir| watch_dir(sub_dir, option) if (File::directory?(sub_dir) == true) } end |