提交 81f78609 编写于 作者: N Neil Matatall 提交者: oreoshake

Move to util class

上级 7191dae1
......@@ -4,6 +4,7 @@ require 'brakeman/processors/output_processor'
require 'brakeman/util'
require 'terminal-table'
require 'highline/system_extensions'
require "csv"
if CSV.const_defined? :Reader
# Ruby 1.8 compatible
......@@ -617,26 +618,4 @@ class Brakeman::Report
template = ERB.new(content)
template.result(bind)
end
def truncate str
@terminal_width ||= ::HighLine::SystemExtensions::terminal_size[0]
lines = str.lines
lines.map do |line|
if line.chomp.length > @terminal_width
line[0..(@terminal_width - 3)] + ">>"
else
line
end
end.join
end
# rely on Terminal::Table to build the structure, extract the data out in CSV format
def table_to_csv table
output = CSV.generate_line(table.headings.cells.map{|cell| cell.to_s.strip})
table.rows.each do |row|
output << CSV.generate_line(row.cells.map{|cell| cell.to_s.strip})
end
output
end
end
......@@ -324,4 +324,26 @@ module Brakeman::Util
context
end
def truncate str
@terminal_width ||= ::HighLine::SystemExtensions::terminal_size[0]
lines = str.lines
lines.map do |line|
if line.chomp.length > @terminal_width
line[0..(@terminal_width - 3)] + ">>"
else
line
end
end.join
end
# rely on Terminal::Table to build the structure, extract the data out in CSV format
def table_to_csv table
output = CSV.generate_line(table.headings.cells.map{|cell| cell.to_s.strip})
table.rows.each do |row|
output << CSV.generate_line(row.cells.map{|cell| cell.to_s.strip})
end
output
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册