Class: Circle::CLI::Watcher

Inherits:
Object
  • Object
show all
Defined in:
lib/circle/cli/watcher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&displayer) ⇒ Watcher

Returns a new instance of Watcher.



6
7
8
9
# File 'lib/circle/cli/watcher.rb', line 6

def initialize(&displayer)
  @displayer = displayer
  @preloader = -> {}
end

Instance Attribute Details

#displayerObject (readonly)

Returns the value of attribute displayer.



4
5
6
# File 'lib/circle/cli/watcher.rb', line 4

def displayer
  @displayer
end

#preloaderObject (readonly)

Returns the value of attribute preloader.



4
5
6
# File 'lib/circle/cli/watcher.rb', line 4

def preloader
  @preloader
end

Instance Method Details

#displayObject



19
20
21
# File 'lib/circle/cli/watcher.rb', line 19

def display
  displayer.call
end

#poll(polling_frequency) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/circle/cli/watcher.rb', line 23

def poll(polling_frequency)
  loop do
    display
    sleep polling_frequency
    preload
    clear
  end
rescue Interrupt
  exit 0
end

#preloadObject



15
16
17
# File 'lib/circle/cli/watcher.rb', line 15

def preload
  preloader.call
end

#to_preload(&preloader) ⇒ Object



11
12
13
# File 'lib/circle/cli/watcher.rb', line 11

def to_preload(&preloader)
  @preloader = preloader
end