Class: FSEvent::Stream

Inherits:
Object
  • Object
show all
Defined in:
lib/rb-fsevent-legacy/stream.rb

Class Method Summary collapse

Instance Method Summary collapse

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

Returns:

  • (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

#emptyObject



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

#eventsObject



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

#killallObject



68
69
70
71
72
# File 'lib/rb-fsevent-legacy/stream.rb', line 68

def killall
  @streams.each do |s|
    s.stop
  end
end

#latencyObject



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

#pathsObject



37
38
39
# File 'lib/rb-fsevent-legacy/stream.rb', line 37

def paths
  @streams.collect { |s| s.path }
end

#runObject



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

Returns:

  • (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

#statusObject



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

#stopObject



104
105
106
# File 'lib/rb-fsevent-legacy/stream.rb', line 104

def stop
  @run = false
end

#streamsObject



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