Class: FaaStRuby::Local::Listener

Inherits:
Object
  • Object
show all
Includes:
Logger
Defined in:
lib/faastruby/local/listeners/listener.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logger

#debug, puts, #puts

Constructor Details

#initialize(directory:, queue:) ⇒ Listener

Returns a new instance of Listener.



16
17
18
19
20
21
# File 'lib/faastruby/local/listeners/listener.rb', line 16

def initialize(directory:, queue:)
  debug "initialize(directory: #{directory.inspect}, queue: #{queue.inspect})"
  @directory = directory
  @queue = queue
  @listener = ::Listen.to(directory, &callback)
end

Instance Attribute Details

#directoryObject

Returns the value of attribute directory.



15
16
17
# File 'lib/faastruby/local/listeners/listener.rb', line 15

def directory
  @directory
end

#listenerObject

Returns the value of attribute listener.



15
16
17
# File 'lib/faastruby/local/listeners/listener.rb', line 15

def listener
  @listener
end

#queueObject

Returns the value of attribute queue.



15
16
17
# File 'lib/faastruby/local/listeners/listener.rb', line 15

def queue
  @queue
end

Class Method Details

.functions_listenerObject



4
5
6
# File 'lib/faastruby/local/listeners/listener.rb', line 4

def self.functions_listener
  @@functions_listener ||= []
end

.opal_listenerObject



10
11
12
# File 'lib/faastruby/local/listeners/listener.rb', line 10

def self.opal_listener
  @@opal_listener ||= []
end

.public_listenerObject



7
8
9
# File 'lib/faastruby/local/listeners/listener.rb', line 7

def self.public_listener
  @@public_listener ||= []
end

Instance Method Details

#callbackObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/faastruby/local/listeners/listener.rb', line 33

def callback
  debug "callback"
  Proc.new do |modified, added, removed|
    begin
      modified.each do |file|
        queue.push ListenerEvent.new(type: :modified, full_path: file, listened_directory: @directory)
      end
      added.each do |file|
        queue.push ListenerEvent.new(type: :added, full_path: file, listened_directory: @directory)
      end
      removed.each do |file|
        queue.push ListenerEvent.new(type: :removed, full_path: file, listened_directory: @directory)
      end
    rescue StandardError => e
      String.disable_colorization = true
      STDOUT.puts e.full_message
      String.disable_colorization = false
      next
    end
  end
end

#startObject



23
24
25
26
# File 'lib/faastruby/local/listeners/listener.rb', line 23

def start
  debug "start"
  listener.start
end

#stopObject



28
29
30
31
# File 'lib/faastruby/local/listeners/listener.rb', line 28

def stop
  debug "stop"
  listener.stop
end