Class: INotify::Event
- Inherits:
-
Object
- Object
- INotify::Event
- Defined in:
- lib/rb-inotify/event.rb
Overview
An event caused by a change on the filesystem. Each Watcher can fire many events, which are passed to that watcher's callback.
Instance Attribute Summary collapse
-
#name ⇒ String
readonly
The name of the file that the event occurred on.
-
#notifier ⇒ Notifier
readonly
The Notifier that fired this event.
-
#related ⇒ Array<Event>
readonly
A list of other events that are related to this one.
Instance Method Summary collapse
-
#absolute_name ⇒ String
The absolute path of the file that the event occurred on.
-
#flags ⇒ Array<Symbol>
Returns the flags that describe this event.
-
#size ⇒ Fixnum
Returns the size of this event object in bytes, including the #name string.
-
#watcher ⇒ Watcher
Returns the Watcher that fired this event.
Instance Attribute Details
#name ⇒ String (readonly)
The name of the file that the event occurred on.
This is only set for events that occur on files in directories;
otherwise, it's ""
.
Similarly, if the event is being fired for the directory itself
the name will be ""
This pathname is relative to the enclosing directory.
For the absolute pathname, use #absolute_name.
Note that when the :recursive
flag is passed to Notifier#watch,
events in nested subdirectories will still have a #name
field
relative to their immediately enclosing directory.
For example, an event on the file "foo/bar/baz"
will have name "baz"
.
28 29 30 |
# File 'lib/rb-inotify/event.rb', line 28 def name @name end |
#notifier ⇒ Notifier (readonly)
The Notifier that fired this event.
33 34 35 |
# File 'lib/rb-inotify/event.rb', line 33 def notifier @notifier end |
#related ⇒ Array<Event> (readonly)
A list of other events that are related to this one.
Currently, this is only used for files that are moved within the same directory:
the :moved_from
and the :moved_to
events will be related.
11 12 13 |
# File 'lib/rb-inotify/event.rb', line 11 def @related end |
Instance Method Details
#absolute_name ⇒ String
The absolute path of the file that the event occurred on.
This is actually only as absolute as the path passed to the Watcher that created this event. However, it is relative to the working directory, assuming that hasn't changed since the watcher started.
66 67 68 69 |
# File 'lib/rb-inotify/event.rb', line 66 def absolute_name return watcher.path if name.empty? return File.join(watcher.path, name) end |
#flags ⇒ Array<Symbol>
Returns the flags that describe this event.
This is generally similar to the input to Notifier#watch,
except that it won't contain options flags nor :all_events
,
and it may contain one or more of the following flags:
:unmount
: The filesystem containing the watched file or directory was unmounted.
:ignored
: The watcher was closed, or the watched file or directory was deleted.
:isdir
: The subject of this event is a directory.
86 87 88 |
# File 'lib/rb-inotify/event.rb', line 86 def flags @flags ||= Native::Flags.from_mask(@native[:mask]) end |
#size ⇒ Fixnum
Returns the size of this event object in bytes, including the #name string.
135 136 137 |
# File 'lib/rb-inotify/event.rb', line 135 def size @native.size + @native[:len] end |