Class: Rfam::Monitor

Inherits:
Object
  • Object
show all
Defined in:
lib/rfam/monitor.rb

Constant Summary collapse

DEFAULT_INTERVAL =
1000

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path:, interval: nil) ⇒ Monitor

Returns a new instance of Monitor.



18
19
20
21
22
23
24
25
# File 'lib/rfam/monitor.rb', line 18

def initialize(path:, interval: nil)
  @path = path
  @interval = interval || DEFAULT_INTERVAL
  @listener = Listener.new
  @observer = Rfam::FileAlterationObserver.new(path)
  @observer.addListener(@listener)
  @monitor = Rfam::FileAlterationMonitor.new(@interval, @observer)
end

Instance Attribute Details

#intervalObject (readonly)

Returns the value of attribute interval.



16
17
18
# File 'lib/rfam/monitor.rb', line 16

def interval
  @interval
end

#listenerObject (readonly)

Returns the value of attribute listener.



16
17
18
# File 'lib/rfam/monitor.rb', line 16

def listener
  @listener
end

#monitorObject (readonly)

Returns the value of attribute monitor.



16
17
18
# File 'lib/rfam/monitor.rb', line 16

def monitor
  @monitor
end

#observerObject (readonly)

Returns the value of attribute observer.



16
17
18
# File 'lib/rfam/monitor.rb', line 16

def observer
  @observer
end

#pathObject (readonly)

Returns the value of attribute path.



16
17
18
# File 'lib/rfam/monitor.rb', line 16

def path
  @path
end

Class Method Details

.run(*args) ⇒ Object



12
13
14
# File 'lib/rfam/monitor.rb', line 12

def self.run(*args)
  new(*args).run
end

.start(*args) ⇒ Object



8
9
10
# File 'lib/rfam/monitor.rb', line 8

def self.start(*args)
  new(*args).start
end

Instance Method Details

#runObject



35
36
37
38
39
40
41
42
# File 'lib/rfam/monitor.rb', line 35

def run
  begin
    start
    sleep
  ensure
    stop
  end
end

#startObject



27
28
29
# File 'lib/rfam/monitor.rb', line 27

def start
  monitor.start
end

#stopObject



31
32
33
# File 'lib/rfam/monitor.rb', line 31

def stop
  monitor.stop(0)
end