Class: RShade::Formatter::Html

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

Constant Summary collapse

FILE_NAME =
'stacktrace.html'.freeze
TEMPLATE =
'html/template.html.erb'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Html

Returns a new instance of Html.



10
11
12
# File 'lib/rshade/formatter/html.rb', line 10

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

Instance Attribute Details

#formatterObject (readonly)

Returns the value of attribute formatter.



6
7
8
# File 'lib/rshade/formatter/html.rb', line 6

def formatter
  @formatter
end

Instance Method Details

#call(event_store) ⇒ Object

Parameters:



15
16
17
18
19
20
# File 'lib/rshade/formatter/html.rb', line 15

def call(event_store)
  data = formatter.call(event_store)
  erb_template = ERB.new(template)
  content = erb_template.result_with_hash({json: data.to_json})
  write_to_file(content)
end

#templateObject



28
29
30
# File 'lib/rshade/formatter/html.rb', line 28

def template
  @template ||=::File.read(::File.join(::RShade::Config.root_dir, TEMPLATE))
end

#write_to_file(data) ⇒ Object



22
23
24
25
26
# File 'lib/rshade/formatter/html.rb', line 22

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