Class: ScribeIt::Source

Inherits:
Object
  • Object
show all
Defined in:
lib/scribeit/source.rb

Defined Under Namespace

Classes: Reader

Instance Method Summary collapse

Constructor Details

#initialize(file, category, &block) ⇒ Source

Returns a new instance of Source.



3
4
5
6
7
8
# File 'lib/scribeit/source.rb', line 3

def initialize(file, category, &block)
  @logger = ScribeIt::Log.new STDERR
  @file = file
  @callback = block
  @category = category
end

Instance Method Details

#receive(filetail, event) ⇒ Object



15
16
17
18
19
# File 'lib/scribeit/source.rb', line 15

def receive(filetail, event)
  @logger.debug "File #{@file} got event: #{event.inspect}"
  e = {:event => event, :category => @category}
  @callback.call e
end

#registerObject



10
11
12
13
# File 'lib/scribeit/source.rb', line 10

def register
  @logger.info "Registering #{@file}"
  EventMachine::FileGlobWatchTail.new(@file, Reader, interval=60, exclude=[], receiver=self)
end