Class: Octodown::Support::Services::Riposter

Inherits:
Object
  • Object
show all
Defined in:
lib/octodown/support/services/riposter.rb

Class Method Summary collapse

Class Method Details

.call(file, &listener_callback) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/octodown/support/services/riposter.rb', line 7

def self.call(file, &listener_callback)
  require 'listen'

  path = File.dirname(File.expand_path(file.path))
  escaped_path = Regexp.escape(file.path)
  regex = Regexp.new("^#{escaped_path}$")

  @listener ||= Listen.to(path, only: regex) do |modified, added, _rm|
    listener_callback.call if modified.any? || added.any?
  end

  @listener.start
end