ruby-inotify 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. data/doc/classes/Inotify/Event.html +206 -0
  2. data/doc/classes/Inotify/Event.src/M000005.html +18 -0
  3. data/doc/classes/Inotify/Event.src/M000006.html +18 -0
  4. data/doc/classes/Inotify/Event.src/M000007.html +18 -0
  5. data/doc/classes/Inotify/Event.src/M000008.html +18 -0
  6. data/doc/classes/Inotify/Event.src/M000009.html +18 -0
  7. data/doc/classes/Inotify/Event.src/M000010.html +18 -0
  8. data/doc/classes/Inotify/Event.src/M000011.html +18 -0
  9. data/doc/classes/Inotify/Event.src/M000012.html +23 -0
  10. data/doc/classes/Inotify/Event.src/M000013.html +23 -0
  11. data/doc/classes/Inotify/Event.src/M000014.html +18 -0
  12. data/doc/classes/Inotify/Event.src/M000015.html +23 -0
  13. data/doc/classes/Inotify/EventStruct.html +117 -0
  14. data/doc/classes/Inotify.html +476 -0
  15. data/doc/classes/Inotify.src/M000001.html +18 -0
  16. data/doc/classes/Inotify.src/M000002.html +18 -0
  17. data/doc/classes/Inotify.src/M000003.html +18 -0
  18. data/doc/classes/Inotify.src/M000004.html +22 -0
  19. data/doc/classes/Inotify.src/M000005.html +21 -0
  20. data/doc/classes/Inotify.src/M000006.html +21 -0
  21. data/doc/classes/Inotify.src/M000007.html +19 -0
  22. data/doc/classes/Inotify.src/M000008.html +18 -0
  23. data/doc/classes/Inotify.src/M000009.html +18 -0
  24. data/doc/classes/Inotify.src/M000010.html +18 -0
  25. data/doc/classes/Inotify.src/M000011.html +21 -0
  26. data/doc/classes/Inotify.src/M000012.html +21 -0
  27. data/doc/classes/Test1.html +212 -0
  28. data/doc/classes/Test1.src/M000001.html +18 -0
  29. data/doc/classes/Test1.src/M000002.html +18 -0
  30. data/doc/classes/Test1.src/M000003.html +18 -0
  31. data/doc/classes/Test1.src/M000004.html +20 -0
  32. data/doc/classes/Test1.src/M000005.html +30 -0
  33. data/doc/classes/Test1.src/M000006.html +18 -0
  34. data/doc/created.rid +1 -0
  35. data/doc/files/examples/watcher_rb.html +109 -0
  36. data/doc/files/lib/inotify/inotify_native_rb.html +109 -0
  37. data/doc/files/lib/inotify/version_rb.html +108 -0
  38. data/doc/files/lib/inotify_rb.html +108 -0
  39. data/doc/files/tests/test_1_rb.html +109 -0
  40. data/doc/fr_class_index.html +28 -0
  41. data/doc/fr_file_index.html +27 -0
  42. data/doc/fr_method_index.html +34 -0
  43. data/doc/index.html +24 -0
  44. data/doc/rdoc-style.css +208 -0
  45. data/lib/inotify/inotify_native.rb +103 -23
  46. data/ruby-inotify.gemspec +1 -1
  47. metadata +47 -4
  48. data/lib/inotify/version.rb +0 -3
@@ -1,38 +1,78 @@
1
1
  require 'rubygems'
2
2
  require 'ffi'
3
3
 
4
+ # The Inotify class is a simple wrapper around the inotify functionality provided by the OS
4
5
  class Inotify
5
6
 
7
+ VERSION = "1.0.1" # :nodoc:
8
+
6
9
  extend FFI::Library
7
10
  ffi_lib FFI::Platform::LIBC
8
11
 
9
- MAX_NAME_SIZE = 4096
12
+ # The maximum supported size of the name argument in the inotify event structure
13
+ MAX_NAME_SIZE = 4096 # :nodoc:
10
14
 
15
+ # File was accessed (read) (*)
11
16
  ACCESS = 0x00000001
17
+ # File was modified (*)
12
18
  MODIFY = 0x00000002
13
- ATTRIB = 0x00000004
14
- CLOSE_WRITE = 0x00000008
19
+ # Metadata changed, e.g., permissions, timestamps,
20
+ # extended attributes, link count (since Linux 2.6.25),
21
+ # UID, GID, etc. (*)
22
+ ATTRIB = 0x00000004
23
+ # File opened for writing was closed (*)
24
+ CLOSE_WRITE = 0x00000008
25
+ # File not opened for writing was closed (*)
15
26
  CLOSE_NOWRITE = 0x00000010
27
+ # File was opened (*)
16
28
  OPEN = 0x00000020
29
+ # File moved out of watched directory (*)
17
30
  MOVED_FROM = 0x00000040
31
+ # File moved into watched directory (*)
18
32
  MOVED_TO = 0x00000080
33
+ # File/directory created in watched directory (*)
19
34
  CREATE = 0x00000100
35
+ # File/directory deleted from watched directory (*)
20
36
  DELETE = 0x00000200
37
+ # Watched file/directory was itself deleted
21
38
  DELETE_SELF = 0x00000400
39
+ # Watched file/directory was itself moved
22
40
  MOVE_SELF = 0x00000800
23
- # Events sent by the kernel.
41
+ # File system containing watched object was unmounted
24
42
  UNMOUNT = 0x00002000
43
+ # Event queue overflowed (wd is -1 for this event)
25
44
  Q_OVERFLOW = 0x00004000
45
+ # Watch was removed explicitly (inotify_rm_watch(2)) or
46
+ # automatically (file was deleted, or file system was
47
+ # unmounted)
26
48
  IGNORED = 0x00008000
49
+ # (since Linux 2.6.15) Only watch pathname if it is a directory
27
50
  ONLYDIR = 0x01000000
51
+ # (since Linux 2.6.15) Don't dereference pathname if it is a symbolic link
28
52
  DONT_FOLLOW = 0x02000000
29
- MASK_ADD = 0x20000000
30
- # special flags
53
+ # (since Linux 2.6.36)
54
+ # By default, when watching events on the children of a
55
+ # directory, events are generated for children even after
56
+ # they have been unlinked from the directory. This can
57
+ # result in large numbers of uninteresting events for some
58
+ # applications (e.g., if watching /tmp, in which many
59
+ # applications create temporary files whose names are
60
+ # immediately unlinked). Specifying IN_EXCL_UNLINK
61
+ # changes the default behavior, so that events are not
62
+ # generated for children after they have been unlinked
63
+ # from the watched directory.
64
+ EXCL_UNLINK = 0x04000000
65
+ # Add (OR) events to watch mask for this pathname if it
66
+ # already exists (instead of replacing mask)
67
+ MASK_ADD = 0x20000000
68
+ # Subject of this event is a directory
31
69
  ISDIR = 0x40000000
70
+ # Monitor pathname for one event, then remove from watch list
32
71
  ONESHOT = 0x80000000
33
- # helper events
34
- CLOSE = (CLOSE_WRITE | CLOSE_NOWRITE)
35
- MOVE = (MOVED_FROM | MOVED_TO)
72
+ # Both of the close events
73
+ CLOSE = (CLOSE_WRITE | CLOSE_NOWRITE)
74
+ # Both of the move events
75
+ MOVE = (MOVED_FROM | MOVED_TO)
36
76
  #All of the events
37
77
  ALL_EVENTS = (ACCESS | MODIFY | ATTRIB | CLOSE_WRITE | \
38
78
  CLOSE_NOWRITE | OPEN | MOVED_FROM | \
@@ -43,33 +83,54 @@ require 'ffi'
43
83
  attach_function :inotify_rm_watch, [:int, :uint32], :int
44
84
  attach_function :read, [:int, :pointer, :size_t], :ssize_t
45
85
  attach_function :inotify_close, :close, [:int], :int
46
- def initialize
86
+
87
+ # When creating a new instance of this class, an inotify instance is created in the OS.
88
+ def initialize # :nodoc:
47
89
  @fd = self.inotify_init
48
90
  @io = FFI::IO.for_fd(@fd)
49
91
  end
50
- def add_watch(string, uint32)
51
- self.inotify_add_watch(@fd, string, uint32)
92
+
93
+ # add_watch() adds a new watch, or modifies an existing watch, for the
94
+ # file whose location is specified in pathname; the caller must have read
95
+ # permission for this file. The events to be
96
+ # monitored for pathname are specified in the mask bit-mask argument.
97
+ # On success, inotify_add_watch() returns a nonnegative watch descriptor (wd), or
98
+ # -1 if an error occurred.
99
+ def add_watch(pathname, mask)
100
+ self.inotify_add_watch(@fd, pathname, mask)
52
101
  end
53
- def rm_watch(uint32)
54
- self.inotify_rm_watch(@fd, uint32)
102
+
103
+ # rm_watch() removes the watch associated with the watch descriptor wd.
104
+ # On success, returns zero, or -1 if an error occurred.
105
+ def rm_watch(wd)
106
+ self.inotify_rm_watch(@fd, wd)
55
107
  end
108
+
109
+ # close() stops the processing of events and closes the
110
+ # inotify instance in the OS
56
111
  def close
57
112
  self.inotify_close(@fd)
58
113
  end
114
+
115
+ # each_event() provides an easy way to loop over all events as they occur
59
116
  def each_event
60
117
  loop do
61
118
  ready = IO.select([@io], nil, nil, nil)
62
- yield self.read_event
119
+ event = self.read_event
120
+ yield event
63
121
  end
64
122
  end
65
- def read_event
123
+
124
+ # read_event() attempts to read the next inotify event from the OS
125
+ def read_event # :nodoc:
66
126
  buf = FFI::Buffer.alloc_out(EventStruct.size + MAX_NAME_SIZE, 1, false)
67
127
  ev = EventStruct.new(buf)
68
128
  n = self.read(@fd, buf, buf.total)
69
129
  Event.new(ev, buf)
70
130
  end
71
131
 
72
- class EventStruct < FFI::Struct
132
+ # Internal class needed for FFI support
133
+ class EventStruct < FFI::Struct # :nodoc:
73
134
  layout(
74
135
  :wd, :int,
75
136
  :mask, :uint32,
@@ -77,20 +138,39 @@ require 'ffi'
77
138
  :len, :uint32)
78
139
  end
79
140
 
141
+ # The Inotify::Event class is used by Inotify when calling Inotify each_event method
80
142
  class Event
81
- def initialize(struct, buf)
143
+
144
+ def initialize(struct, buf) # :nodoc:
82
145
  @struct, @buf = struct, buf
83
146
  end
84
147
 
85
- define_method(:wd) { @struct[:wd] }
86
- define_method(:mask) { @struct[:mask] }
87
- define_method(:cookie) { @struct[:cookie] }
88
- define_method(:len) { @struct[:len] }
148
+ # Returns the watch descriptor (wd) associated with the event
149
+ def wd
150
+ @struct[:wd]
151
+ end
152
+
153
+ # Returns the mask describing the event
154
+ def mask
155
+ @struct[:mask]
156
+ end
157
+
158
+ # Returns the cookie associated with the event. If multiple events are triggered from the
159
+ # same action (such as renaming a file or directory), this value will be the same.
160
+ def cookie
161
+ @struct[:cookie]
162
+ end
163
+
164
+ def len # :nodoc:
165
+ @struct[:len]
166
+ end
167
+
168
+ # Returns the file name associated with the event, if applicable
89
169
  def name
90
170
  @struct[:len] > 0 ? @buf.get_string(16, @struct[:len]) : ''
91
171
  end
92
172
 
93
- def inspect
173
+ def inspect # :nodoc:
94
174
  "<%s name=%s mask=%s wd=%s>" % [
95
175
  self.class,
96
176
  self.name,
data/ruby-inotify.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  $:.push File.expand_path("../lib", __FILE__)
3
- require "inotify/version"
3
+ require "inotify/inotify_native"
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "ruby-inotify"
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-inotify
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 0
10
- version: 1.0.0
9
+ - 1
10
+ version: 1.0.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Aria Stewart
@@ -48,10 +48,53 @@ files:
48
48
  - Gemfile
49
49
  - README.md
50
50
  - Rakefile
51
+ - doc/classes/Inotify.html
52
+ - doc/classes/Inotify.src/M000001.html
53
+ - doc/classes/Inotify.src/M000002.html
54
+ - doc/classes/Inotify.src/M000003.html
55
+ - doc/classes/Inotify.src/M000004.html
56
+ - doc/classes/Inotify.src/M000005.html
57
+ - doc/classes/Inotify.src/M000006.html
58
+ - doc/classes/Inotify.src/M000007.html
59
+ - doc/classes/Inotify.src/M000008.html
60
+ - doc/classes/Inotify.src/M000009.html
61
+ - doc/classes/Inotify.src/M000010.html
62
+ - doc/classes/Inotify.src/M000011.html
63
+ - doc/classes/Inotify.src/M000012.html
64
+ - doc/classes/Inotify/Event.html
65
+ - doc/classes/Inotify/Event.src/M000005.html
66
+ - doc/classes/Inotify/Event.src/M000006.html
67
+ - doc/classes/Inotify/Event.src/M000007.html
68
+ - doc/classes/Inotify/Event.src/M000008.html
69
+ - doc/classes/Inotify/Event.src/M000009.html
70
+ - doc/classes/Inotify/Event.src/M000010.html
71
+ - doc/classes/Inotify/Event.src/M000011.html
72
+ - doc/classes/Inotify/Event.src/M000012.html
73
+ - doc/classes/Inotify/Event.src/M000013.html
74
+ - doc/classes/Inotify/Event.src/M000014.html
75
+ - doc/classes/Inotify/Event.src/M000015.html
76
+ - doc/classes/Inotify/EventStruct.html
77
+ - doc/classes/Test1.html
78
+ - doc/classes/Test1.src/M000001.html
79
+ - doc/classes/Test1.src/M000002.html
80
+ - doc/classes/Test1.src/M000003.html
81
+ - doc/classes/Test1.src/M000004.html
82
+ - doc/classes/Test1.src/M000005.html
83
+ - doc/classes/Test1.src/M000006.html
84
+ - doc/created.rid
85
+ - doc/files/examples/watcher_rb.html
86
+ - doc/files/lib/inotify/inotify_native_rb.html
87
+ - doc/files/lib/inotify/version_rb.html
88
+ - doc/files/lib/inotify_rb.html
89
+ - doc/files/tests/test_1_rb.html
90
+ - doc/fr_class_index.html
91
+ - doc/fr_file_index.html
92
+ - doc/fr_method_index.html
93
+ - doc/index.html
94
+ - doc/rdoc-style.css
51
95
  - examples/watcher.rb
52
96
  - lib/inotify.rb
53
97
  - lib/inotify/inotify_native.rb
54
- - lib/inotify/version.rb
55
98
  - ruby-inotify.gemspec
56
99
  - tests/test_1.rb
57
100
  homepage: http://dinhe.net/~aredridel/projects/ruby/ruby-inotify
@@ -1,3 +0,0 @@
1
- module Inotify
2
- VERSION = "1.0.0"
3
- end