Class: Failbot::FileBackend

Inherits:
Object
  • Object
show all
Defined in:
lib/failbot/file_backend.rb

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ FileBackend

Returns a new instance of FileBackend.



5
6
7
8
9
10
11
# File 'lib/failbot/file_backend.rb', line 5

def initialize(path)
  @path = path

  if path.to_s.empty?
    raise ArgumentError, "FAILBOT_BACKEND_FILE_PATH setting required."
  end
end

Instance Method Details

#pingObject

Raises:

  • (StandardError)


27
28
29
# File 'lib/failbot/file_backend.rb', line 27

def ping
  raise StandardError, "cannot write to #{@path}" unless File.writable?(@path)
end

#report(data) ⇒ Object



13
14
15
16
17
# File 'lib/failbot/file_backend.rb', line 13

def report(data)
  File.open(@path, 'a') do |file|
    file.puts(Yajl.dump(data))
  end
end

#reportsObject



19
20
21
22
23
24
25
# File 'lib/failbot/file_backend.rb', line 19

def reports
  reports = []
  File.foreach(@path) do |line|
    reports << Yajl.load(line)
  end
  reports
end