Class: Sinotify::PrimEvent
- Inherits:
-
Object
- Object
- Sinotify::PrimEvent
- Defined in:
- lib/sinotify/prim_event.rb,
ext/src/sinotify.c
Overview
Sinotify::PrimEvent is a ruby wrapper for an inotify event Use the Sinotify::PrimNotifier to register to listen for these Events.
Most users of Sinotify will not want to listen for prim events, instead opting to use a Sinotify::Notifier to listen for Sinotify::Events. See docs for those classes.
Methods :name, :mask, and :wd defined in sinotify.c
For convenience, inotify masks are represented in the PrimEvent as an ‘etype’, which is just a ruby symbol corresponding to the mask. For instance, a mask represented as Sinotify::MODIFY has an etype of :modify. You can still get the mask if you want the ‘raw’ int mask value. In other words: <pre>
$ irb
>> require 'sinotify'
=> true
>> Sinotify::MODIFY
=> 2
>> Sinotify::Event.etype_from_mask(Sinotify::MODIFY)
=> :modify
>> Sinotify::Event.mask_from_etype(:modify)
=> 2
</pre>
See docs for Sinotify::Event class for full list of supported event symbol types and their symbols.
Constant Summary collapse
- @@mask_to_etype_map =
map the constants defined in the ‘c’ lib to ruby symbols
{ Sinotify::PrimEvent::CREATE => :create, Sinotify::PrimEvent::MOVE => :move, Sinotify::PrimEvent::ACCESS => :access, Sinotify::PrimEvent::MODIFY => :modify, Sinotify::PrimEvent::ATTRIB => :attrib, Sinotify::PrimEvent::CLOSE_WRITE => :close_write, Sinotify::PrimEvent::CLOSE_NOWRITE => :close_nowrite, Sinotify::PrimEvent::OPEN => :open, Sinotify::PrimEvent::MOVED_FROM => :moved_from, Sinotify::PrimEvent::MOVED_TO => :moved_to, Sinotify::PrimEvent::DELETE => :delete, Sinotify::PrimEvent::DELETE_SELF => :delete_self, Sinotify::PrimEvent::MOVE_SELF => :move_self, Sinotify::PrimEvent::UNMOUNT => :unmount, Sinotify::PrimEvent::Q_OVERFLOW => :q_overflow, Sinotify::PrimEvent::IGNORED => :ignored, Sinotify::PrimEvent::CLOSE => :close, Sinotify::PrimEvent::MASK_ADD => :mask_add, Sinotify::PrimEvent::ISDIR => :isdir, Sinotify::PrimEvent::ONLYDIR => :onlydir, Sinotify::PrimEvent::DONT_FOLLOW => :dont_follow, Sinotify::PrimEvent::ONESHOT => :oneshot, Sinotify::PrimEvent::ALL_EVENTS => :all_events, }
- @@etype_to_mask_map =
{}
Class Method Summary collapse
Instance Method Summary collapse
- #etypes ⇒ Object
-
#has_etype?(etype) ⇒ Boolean
Return whether this event has etype specified.
- #inspect ⇒ Object
- #mask ⇒ Object
- #name ⇒ Object
- #prim_mask ⇒ Object
- #prim_name ⇒ Object
- #prim_wd ⇒ Object
-
#recognized? ⇒ Boolean
When first creating a watch, inotify sends a bunch of events that have masks don’t seem to match up w/ any of the masks defined in inotify.h.
- #watch_descriptor ⇒ Object
- #wd ⇒ Object
Class Method Details
.all_etypes ⇒ Object
71 72 73 |
# File 'lib/sinotify/prim_event.rb', line 71 def self.all_etypes @@mask_to_etype_map.values.sort{|e1,e2| e1.to_s <=> e2.to_s} end |
.etype_from_mask(mask) ⇒ Object
63 64 65 |
# File 'lib/sinotify/prim_event.rb', line 63 def self.etype_from_mask(mask) @@mask_to_etype_map[mask] end |
.mask_from_etype(etype) ⇒ Object
67 68 69 |
# File 'lib/sinotify/prim_event.rb', line 67 def self.mask_from_etype(etype) @@etype_to_mask_map[etype] end |
Instance Method Details
#etypes ⇒ Object
99 100 101 |
# File 'lib/sinotify/prim_event.rb', line 99 def etypes @etypes ||= self.class.all_etypes.select{|et| self.has_etype?(et) } end |
#has_etype?(etype) ⇒ Boolean
Return whether this event has etype specified
94 95 96 97 |
# File 'lib/sinotify/prim_event.rb', line 94 def has_etype?(etype) mask_for_etype = self.class.mask_from_etype(etype) return (self.mask & mask_for_etype).eql?(mask_for_etype) end |
#inspect ⇒ Object
107 108 109 |
# File 'lib/sinotify/prim_event.rb', line 107 def inspect "<#{self.class} :name => '#{self.name}', :etypes => #{self.etypes.inspect}, :mask => #{self.mask.to_s(16)}, :watch_descriptor => #{self.watch_descriptor}>" end |
#mask ⇒ Object
83 84 85 |
# File 'lib/sinotify/prim_event.rb', line 83 def mask @mask ||= self.prim_mask end |
#name ⇒ Object
75 76 77 |
# File 'lib/sinotify/prim_event.rb', line 75 def name @name ||= self.prim_name end |
#prim_mask ⇒ Object
151 152 153 154 155 |
# File 'ext/src/sinotify.c', line 151
static VALUE rb_inotify_event_mask(VALUE self) {
struct inotify_event *event;
Data_Get_Struct(self, struct inotify_event, event);
return LONG2NUM(event->mask);
}
|
#prim_name ⇒ Object
134 135 136 137 138 139 140 141 142 |
# File 'ext/src/sinotify.c', line 134
static VALUE rb_inotify_event_name(VALUE self) {
struct inotify_event *event;
Data_Get_Struct(self, struct inotify_event, event);
if(event->len) {
return rb_str_new2(event->name);
} else {
return Qnil;
}
}
|
#prim_wd ⇒ Object
144 145 146 147 148 |
# File 'ext/src/sinotify.c', line 144
static VALUE rb_inotify_event_wd(VALUE self) {
struct inotify_event *event;
Data_Get_Struct(self, struct inotify_event, event);
return INT2NUM(event->wd);
}
|
#recognized? ⇒ Boolean
When first creating a watch, inotify sends a bunch of events that have masks don’t seem to match up w/ any of the masks defined in inotify.h. Pass on those.
89 90 91 |
# File 'lib/sinotify/prim_event.rb', line 89 def recognized? return !self.etypes.empty? end |
#watch_descriptor ⇒ Object
103 104 105 |
# File 'lib/sinotify/prim_event.rb', line 103 def watch_descriptor self.wd end |
#wd ⇒ Object
79 80 81 |
# File 'lib/sinotify/prim_event.rb', line 79 def wd @wd ||= self.prim_wd end |