Class: FSEvents::Stream
- Inherits:
-
Object
- Object
- FSEvents::Stream
- Defined in:
- lib/fsevents/stream.rb
Defined Under Namespace
Classes: StreamError
Instance Attribute Summary collapse
-
#allocator ⇒ Object
readonly
Returns the value of attribute allocator.
-
#callback ⇒ Object
readonly
Returns the value of attribute callback.
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#flags ⇒ Object
readonly
Returns the value of attribute flags.
-
#last_event ⇒ Object
readonly
Returns the value of attribute last_event.
-
#latency ⇒ Object
readonly
Returns the value of attribute latency.
-
#paths ⇒ Object
readonly
Returns the value of attribute paths.
-
#since ⇒ Object
readonly
Returns the value of attribute since.
-
#stream ⇒ Object
readonly
Returns the value of attribute stream.
Class Method Summary collapse
Instance Method Summary collapse
- #create ⇒ Object
-
#initialize(*paths, &callback) ⇒ Stream
constructor
A new instance of Stream.
- #invalidate ⇒ Object
- #release ⇒ Object
- #run ⇒ Object
- #schedule ⇒ Object
- #shutdown ⇒ Object
- #start ⇒ Object
- #startup ⇒ Object
- #stop ⇒ Object
- #stream_callback ⇒ Object
- #update_last_event ⇒ Object
Constructor Details
#initialize(*paths, &callback) ⇒ Stream
Returns a new instance of Stream.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/fsevents/stream.rb', line 10 def initialize(*paths, &callback) raise ArgumentError, 'A callback block is required' if callback.nil? @callback = callback = {} = paths.pop if paths.last.is_a?(Hash) paths = Dir.pwd if paths.empty? @allocator = [:allocator] || OSX::KCFAllocatorDefault @context = [:context] || nil @paths = [paths].flatten @since = [:since] || OSX::KFSEventStreamEventIdSinceNow @latency = [:latency] || 1.0 @flags = [:flags] || 0 end |
Instance Attribute Details
#allocator ⇒ Object (readonly)
Returns the value of attribute allocator.
6 7 8 |
# File 'lib/fsevents/stream.rb', line 6 def allocator @allocator end |
#callback ⇒ Object (readonly)
Returns the value of attribute callback.
6 7 8 |
# File 'lib/fsevents/stream.rb', line 6 def callback @callback end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
6 7 8 |
# File 'lib/fsevents/stream.rb', line 6 def context @context end |
#flags ⇒ Object (readonly)
Returns the value of attribute flags.
6 7 8 |
# File 'lib/fsevents/stream.rb', line 6 def flags @flags end |
#last_event ⇒ Object (readonly)
Returns the value of attribute last_event.
5 6 7 |
# File 'lib/fsevents/stream.rb', line 5 def last_event @last_event end |
#latency ⇒ Object (readonly)
Returns the value of attribute latency.
6 7 8 |
# File 'lib/fsevents/stream.rb', line 6 def latency @latency end |
#paths ⇒ Object (readonly)
Returns the value of attribute paths.
6 7 8 |
# File 'lib/fsevents/stream.rb', line 6 def paths @paths end |
#since ⇒ Object (readonly)
Returns the value of attribute since.
6 7 8 |
# File 'lib/fsevents/stream.rb', line 6 def since @since end |
#stream ⇒ Object (readonly)
Returns the value of attribute stream.
5 6 7 |
# File 'lib/fsevents/stream.rb', line 5 def stream @stream end |
Class Method Details
.create(*args, &block) ⇒ Object
64 65 66 67 68 |
# File 'lib/fsevents/stream.rb', line 64 def create(*args, &block) stream = new(*args, &block) stream.create stream end |
.watch(*args, &block) ⇒ Object
70 71 72 73 74 |
# File 'lib/fsevents/stream.rb', line 70 def watch(*args, &block) stream = create(*args, &block) stream.startup stream end |
Instance Method Details
#create ⇒ Object
27 28 29 30 |
# File 'lib/fsevents/stream.rb', line 27 def create @stream = OSX.FSEventStreamCreate(allocator, stream_callback, context, paths, since, latency, flags) raise StreamError, 'Unable to create FSEvents stream.' unless @stream end |
#invalidate ⇒ Object
81 82 83 |
# File 'lib/fsevents/stream.rb', line 81 def invalidate OSX.FSEventStreamInvalidate(stream) end |
#release ⇒ Object
85 86 87 88 |
# File 'lib/fsevents/stream.rb', line 85 def release OSX.FSEventStreamRelease(stream) @stream = nil end |
#run ⇒ Object
96 97 98 |
# File 'lib/fsevents/stream.rb', line 96 def run OSX.CFRunLoopRun end |
#schedule ⇒ Object
45 46 47 |
# File 'lib/fsevents/stream.rb', line 45 def schedule OSX.FSEventStreamScheduleWithRunLoop(stream, OSX.CFRunLoopGetCurrent, OSX::KCFRunLoopDefaultMode) end |
#shutdown ⇒ Object
90 91 92 93 94 |
# File 'lib/fsevents/stream.rb', line 90 def shutdown stop invalidate release end |
#start ⇒ Object
49 50 51 52 |
# File 'lib/fsevents/stream.rb', line 49 def start OSX.FSEventStreamStart(stream) or raise StreamError, 'Could not start stream' update_last_event end |
#startup ⇒ Object
58 59 60 61 |
# File 'lib/fsevents/stream.rb', line 58 def startup schedule start end |
#stop ⇒ Object
77 78 79 |
# File 'lib/fsevents/stream.rb', line 77 def stop OSX.FSEventStreamStop(stream) end |
#stream_callback ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/fsevents/stream.rb', line 32 def stream_callback lambda do |stream, context, event_count, paths, event_flags, event_IDs| paths.regard_as('*') events = [] event_count.times { |i| events << Event.new(event_IDs[i], paths[i], self) } callback.call(events) update_last_event end end |
#update_last_event ⇒ Object
54 55 56 |
# File 'lib/fsevents/stream.rb', line 54 def update_last_event @last_event = Time.now end |