Class: Reacter::FileAdapter
Instance Attribute Summary
Attributes inherited from Adapter
#config, #enable, #type
Instance Method Summary
collapse
Methods inherited from Adapter
create, #disable, #enabled?, #initialize
Instance Method Details
#connect(args = {}) ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/reacter/adapters/file.rb', line 10
def connect(args={})
if @config.get(:filename) == 'stdin'
@_input = STDIN
else
if (readfile = (@config.get('filename') || @config.get('file.read')))
@_input = File.open(File.expand_path(readfile), 'r+')
end
end
if (writefile = @config.get('file.write'))
@_output = File.open(File.expand_path(writefile), 'a')
end
end
|
#disconnect ⇒ Object
46
47
48
|
# File 'lib/reacter/adapters/file.rb', line 46
def disconnect()
raise AdapterExit
end
|
#poll(&block) ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/reacter/adapters/file.rb', line 34
def poll(&block)
if @_input
loop do
disconnect() if @_input.eof?
line = @_input.gets
yield Message.parse(line)
end
else
Util.warn("file: Attempting to poll without a valid input file handle")
end
end
|
#send(message, format = nil) ⇒ Object
24
25
26
27
28
29
30
31
32
|
# File 'lib/reacter/adapters/file.rb', line 24
def send(message, format=nil)
if defined?(@_output)
message = Message.dump(message, format)
@_output.puts(message) if message
@_output.flush()
else
Util.warn("file: Attempting to send without a valid output file handle")
end
end
|