Class: CodeWeb::HtmlReport

Inherits:
Object
  • Object
show all
Defined in:
lib/code_web/html_report.rb

Constant Summary collapse

TEMPLATE =
%{
<html>
<head><style>
table {border-collapse:collapse;}
table, td, th { border:1px solid black;  }
<%- @class_map.each_with_index do |(pattern, color), i| -%>
.f<%=i%>, a.f<%=i%> { color: <%=color%>; }
<%- end -%>
</style>
</head>
<body>
<%- methods_by_name.each do |methods| -%>
  <h2><%=methods.name%></h2>
  <%- methods.group_by(:hash_args?).each do |methods_with_hash| -%>
    <%- if methods_with_hash.hash_args? -%>
      <%- methods_with_hash.group_by(:method_types).each do |methods_with_type| -%>
        <%- display_yield_column = methods_with_type.detect(&:yields?) -%>
        <table>
        <thead><tr>
          <%- methods_with_type.arg_keys.each do |arg| -%>
            <td><%=arg%></td>
          <%- end -%>
          <%- if display_yield_column -%>
          <td>yield?</td>
          <%- end -%>
          <td>ref</td>
        </tr></thead>
        <tbody>
        <%- methods_with_type.group_by(:signature, arg_regex).each do |methods_by_signature| -%>
          <tr>
          <%- methods_with_type.arg_keys.each do |arg| -%>
            <td><%= simplified_argument(methods_by_signature.hash_arg[arg]) %></td>
          <%- end -%>
            <%- if display_yield_column -%>
            <td><%= methods_by_signature.f.yields? %></td>
            <%- end -%>
            <td><%- methods_by_signature.each_with_index do |method, i| -%>
                <%= method_link(method, i+1) %>
            <%- end -%></td>
          </tr>
        <%- end -%>
        </tbody>
        </table>
      <%- end -%>
    <%- else -%>
      <table>
      <tbody>
      <%- methods_with_hash.group_by(:method_types).each do |methods_with_type| -%>
        <%- display_yield_column = methods_with_type.detect(&:yields?) -%>
        <%- methods_with_type.group_by(:signature, nil, :small_signature).each do |methods_by_signature| -%>
          <tr>
          <%- methods_by_signature.f.args.each do |arg| -%>
            <td><%= arg.inspect %></td>
          <%- end -%>
          <%- if display_yield_column -%>
            <td><%= methods_by_signature.f.yields? ? 'yields' : 'no yield'%></td>
          <%- end -%>
            <td><%- methods_by_signature.each_with_index do |method, i| -%>
                <%= method_link(method, i+1) %>
            <%- end -%></td>
          </tr>
        <%- end -%>
      <%- end -%>
      </tbody>
      </table>
    <%- end -%>
  <%- end -%>

<%- end -%>
</body>
</html>
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method_calls, class_map = {}, arg_regex = nil, out = STDOUT) ⇒ HtmlReport

Returns a new instance of HtmlReport.



20
21
22
23
24
25
# File 'lib/code_web/html_report.rb', line 20

def initialize(method_calls, class_map={}, arg_regex=nil, out=STDOUT)
  @method_calls = method_calls
  @class_map = class_map
  @arg_regex = arg_regex
  @out = out
end

Instance Attribute Details

#:class_map(: class_map) ⇒ Map<Regexp,color>

map from regex to class name if the filename that has the method matches the regex, the classname

will get assigned to the link (to emphasize certain files/directories)

Returns:

  • (Map<Regexp,color>)

    regex expressing name of main file



18
# File 'lib/code_web/html_report.rb', line 18

attr_accessor :class_map

#:method_calls(: method_calls) ⇒ Array<MethodCall> (readonly)

list of all the method_Calls

Returns:



9
# File 'lib/code_web/html_report.rb', line 9

attr_accessor :method_calls

#arg_regexObject

Returns the value of attribute arg_regex.



10
11
12
# File 'lib/code_web/html_report.rb', line 10

def arg_regex
  @arg_regex
end

#class_mapObject

Returns the value of attribute class_map.



18
19
20
# File 'lib/code_web/html_report.rb', line 18

def class_map
  @class_map
end

#method_callsObject

Returns the value of attribute method_calls.



9
10
11
# File 'lib/code_web/html_report.rb', line 9

def method_calls
  @method_calls
end

Instance Method Details

#arg_regex?Boolean

Returns:

  • (Boolean)


11
# File 'lib/code_web/html_report.rb', line 11

def arg_regex? ; ! arg_regex.nil? ; end

#methods_by_nameObject

helpers



112
113
114
# File 'lib/code_web/html_report.rb', line 112

def methods_by_name
  MethodList.group_by(method_calls, :short_method_name)
end

#reportObject



100
101
102
103
104
105
106
107
108
# File 'lib/code_web/html_report.rb', line 100

def report
  template = ERB.new(TEMPLATE, nil, "-")
  @out.puts template.result(binding)
rescue => e
  e.backtrace.detect { |l| l =~ /\(erb\):([0-9]+)/ }
  line_no=$1.to_i
  raise RuntimeError, "error in #{__FILE__}:#{line_no+28} #{e}\n\n #{TEMPLATE.split(/\n/)[line_no-1]}\n\n ",
    e.backtrace
end