Class: FSEvent::Stream
- Inherits:
-
Object
- Object
- FSEvent::Stream
- Defined in:
- lib/rb-fsevent-legacy/stream.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add_path(path) ⇒ Object
- #add_paths(paths) ⇒ Object
- #empty ⇒ Object
- #events ⇒ Object
-
#initialize(path = nil, latency = 1.0) ⇒ Stream
constructor
the callback recieves FSEvent objects which describe the events.
- #killall ⇒ Object
- #latency ⇒ Object
- #latency=(val) ⇒ Object
- #paths ⇒ Object
- #run ⇒ Object
- #running? ⇒ Boolean
- #status ⇒ Object
- #stop ⇒ Object
- #streams ⇒ Object
- #watch(path = nil, &block) ⇒ Object
Constructor Details
#initialize(path = nil, latency = 1.0) ⇒ Stream
the callback recieves FSEvent objects which describe the events
10 11 12 13 14 15 16 17 |
# File 'lib/rb-fsevent-legacy/stream.rb', line 10 def initialize(path = nil, latency = 1.0) unless path.nil? @streams = [NativeStream.new(path,Float(latency))] else @streams = [] end @run = false; end |
Class Method Details
.running? ⇒ Boolean
4 5 6 |
# File 'lib/rb-fsevent-legacy/stream.rb', line 4 def running? if NativeStream.timer_events > 0 then true end end |
Instance Method Details
#add_path(path) ⇒ Object
47 48 49 |
# File 'lib/rb-fsevent-legacy/stream.rb', line 47 def add_path path @streams.push(NativeStream.new(path,self.latency)) end |
#add_paths(paths) ⇒ Object
41 42 43 44 45 |
# File 'lib/rb-fsevent-legacy/stream.rb', line 41 def add_paths paths paths.each do |p| self.add_path p end end |
#empty ⇒ Object
33 34 35 |
# File 'lib/rb-fsevent-legacy/stream.rb', line 33 def empty @streams.each { |s| s.stop }.delete_if { |s| not s.running? } end |
#events ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/rb-fsevent-legacy/stream.rb', line 78 def events events = [] @streams.each do |s| s.events do |e| if block_given? events << (yield e) else events << e end end end events.compact end |
#killall ⇒ Object
68 69 70 71 72 |
# File 'lib/rb-fsevent-legacy/stream.rb', line 68 def killall @streams.each do |s| s.stop end end |
#latency ⇒ Object
19 20 21 |
# File 'lib/rb-fsevent-legacy/stream.rb', line 19 def latency @latency || 1.0 end |
#latency=(val) ⇒ Object
23 24 25 |
# File 'lib/rb-fsevent-legacy/stream.rb', line 23 def latency= val @latency = Float(val) end |
#paths ⇒ Object
37 38 39 |
# File 'lib/rb-fsevent-legacy/stream.rb', line 37 def paths @streams.collect { |s| s.path } end |
#run ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/rb-fsevent-legacy/stream.rb', line 92 def run @run = true while @run do self.events do |e| if @call_block @call_block.call(e) end end sleep 1 end end |
#running? ⇒ Boolean
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/rb-fsevent-legacy/stream.rb', line 57 def running? status = @streams.collect { |s| s.running? } if not status.include? true false elsif not status.include? false true else raise StandardError, "native streams are in mixed states" end end |
#status ⇒ Object
51 52 53 54 55 |
# File 'lib/rb-fsevent-legacy/stream.rb', line 51 def status status = @streams.collect do |s| s.running? end end |
#stop ⇒ Object
104 105 106 |
# File 'lib/rb-fsevent-legacy/stream.rb', line 104 def stop @run = false end |
#streams ⇒ Object
74 75 76 |
# File 'lib/rb-fsevent-legacy/stream.rb', line 74 def streams @streams end |
#watch(path = nil, &block) ⇒ Object
27 28 29 30 31 |
# File 'lib/rb-fsevent-legacy/stream.rb', line 27 def watch path = nil, &block @streams.push(NativeStream.new(path,self.latency)) unless path.nil? @call_block = block self end |