Class: Woodchuck::Watcher

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/woodchuck/watcher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(agent, *paths) ⇒ Watcher

Returns a new instance of Watcher.



15
16
17
18
19
20
# File 'lib/woodchuck/watcher.rb', line 15

def initialize(agent, *paths)
  @agent = agent
  @logger = Woodchuck::Logger.new(::STDOUT)
  @tailer = FileWatch::Tail.new
  @paths = paths.flatten
end

Instance Attribute Details

#agentObject

Returns the value of attribute agent.



12
13
14
# File 'lib/woodchuck/watcher.rb', line 12

def agent
  @agent
end

#eventsObject

Returns the value of attribute events.



12
13
14
# File 'lib/woodchuck/watcher.rb', line 12

def events
  @events
end

#loggerObject

Returns the value of attribute logger.



12
13
14
# File 'lib/woodchuck/watcher.rb', line 12

def logger
  @logger
end

#pathsObject

Returns the value of attribute paths.



12
13
14
# File 'lib/woodchuck/watcher.rb', line 12

def paths
  @paths
end

#tailerObject

Returns the value of attribute tailer.



12
13
14
# File 'lib/woodchuck/watcher.rb', line 12

def tailer
  @tailer
end

Instance Method Details

#inspectObject



32
33
34
# File 'lib/woodchuck/watcher.rb', line 32

def inspect
  to_s
end

#startObject



22
23
24
25
26
27
28
29
30
# File 'lib/woodchuck/watcher.rb', line 22

def start
  paths.each do |path|
    tailer.tail(path)
  end
  tailer.subscribe do |path, line|
    event = Woodchuck::Event.new(path, line)
    output.handle(event)
  end
end