Class: RuVim::Stream::Follow

Inherits:
RuVim::Stream show all
Defined in:
lib/ruvim/stream/follow.rb

Instance Attribute Summary collapse

Attributes inherited from RuVim::Stream

#state, #stop_handler

Instance Method Summary collapse

Methods inherited from RuVim::Stream

#command, #live?

Constructor Details

#initialize(path:, buffer_id:, queue:, stop_handler: nil, &notify) ⇒ Follow

Returns a new instance of Follow.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/ruvim/stream/follow.rb', line 7

def initialize(path:, buffer_id:, queue:, stop_handler: nil, &notify)
  super(stop_handler: stop_handler)
  @state = :live
  @watcher = FileWatcher.create(path) do |type, data|
    case type
    when :data
      queue << { type: :follow_data, buffer_id: buffer_id, data: data }
    when :truncated
      queue << { type: :follow_truncated, buffer_id: buffer_id }
    when :deleted
      queue << { type: :follow_deleted, buffer_id: buffer_id }
    end
    notify.call
  end
  @backend = @watcher.backend
  @watcher.start
end

Instance Attribute Details

#backendObject

Returns the value of attribute backend.



5
6
7
# File 'lib/ruvim/stream/follow.rb', line 5

def backend
  @backend
end

#watcherObject

Returns the value of attribute watcher.



5
6
7
# File 'lib/ruvim/stream/follow.rb', line 5

def watcher
  @watcher
end

Instance Method Details

#statusObject



25
26
27
28
29
30
31
# File 'lib/ruvim/stream/follow.rb', line 25

def status
  case @state
  when :live
    @backend == :inotify ? "follow/i" : "follow"
  when :error then "follow/error"
  end
end

#stop!Object



33
34
35
36
37
38
# File 'lib/ruvim/stream/follow.rb', line 33

def stop!
  watcher = @watcher; @watcher = nil
  watcher&.stop
  @backend = nil
  @state = nil
end