Class: RShade::Formatter::File

Inherits:
Object
  • Object
show all
Defined in:
lib/rshade/formatter/file.rb

Constant Summary collapse

FILE_NAME =
'stacktrace.json'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ File

Returns a new instance of File.



7
8
9
# File 'lib/rshade/formatter/file.rb', line 7

def initialize(args={})
  @formatter = args.fetch(:format, Json)
end

Instance Attribute Details

#formatterObject (readonly)

Returns the value of attribute formatter.



4
5
6
# File 'lib/rshade/formatter/file.rb', line 4

def formatter
  @formatter
end

Instance Method Details

#call(event_store) ⇒ Object

Parameters:



12
13
14
15
16
17
18
19
# File 'lib/rshade/formatter/file.rb', line 12

def call(event_store)
  data = formatter.call(event_store)
  if formatter == Json
    write_to_file(JSON.pretty_generate(data))
  else
    write_to_file(data.to_s)
  end
end

#write_to_file(data) ⇒ Object



21
22
23
24
25
# File 'lib/rshade/formatter/file.rb', line 21

def write_to_file(data)
  ::File.open(::File.join(RShade::Config.store_dir, FILE_NAME), "w+") do |f|
    f.write data
  end
end