Module: Fiveruns::Tuneup

Defined in:
lib/fiveruns/tuneup/bar.rb,
lib/fiveruns/tuneup/run.rb,
lib/fiveruns/tuneup/step.rb,
lib/fiveruns/tuneup/panel.rb,
lib/fiveruns/tuneup/helpers.rb,
lib/fiveruns/tuneup/templating.rb,
lib/fiveruns/tuneup/superlative.rb

Defined Under Namespace

Modules: Superlative, Templating Classes: Bar, CalculationError, DisparityStep, Panel, RootStep, Run, Step

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.javascripts_pathObject

Returns the value of attribute javascripts_path.



5
6
7
# File 'lib/fiveruns/tuneup/panel.rb', line 5

def javascripts_path
  @javascripts_path
end

.stylesheets_pathObject

Returns the value of attribute stylesheets_path.



6
7
8
# File 'lib/fiveruns/tuneup/panel.rb', line 6

def stylesheets_path
  @stylesheets_path
end

Class Method Details

TODO: Refactor



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/fiveruns/tuneup/helpers.rb', line 23

def self.editor_link_line(line)
  filename, number, extra = line.match(/^(.+?):(\d+)(?::in\b(.*?))?/)[1, 2]
  in_app, line = strip_root(line)
  name = if line.size > 87
    "…#{CGI.escapeHTML line.sub(/^.*?(.{84})$/, '\1')}"
  else 
    line
  end
  name = if in_app
    if name =~ /`/
      name.sub(/^(.*?)\s+`(.*?)'$/, %q(<span class='tuneup-app-line'>\1</span> `<b class='tuneup-app-line'>\2</b>'))
    else
      %(<span class='tuneup-app-line'>#{name}</span>)
    end
  else
    name.sub(/([^\/\\]+\.\S+:\d+:in)\s+`(.*?)'$/, %q(\1 `<b>\2</b>'))
  end
  %(<a title='%s' href='txmt://open/?url=file://%s&line=%d'>%s</a>%s) % [CGI.escapeHTML(line), filename, number, name, extra]
end

.format_caller(trace) ⇒ Object



4
5
6
7
8
# File 'lib/fiveruns/tuneup/helpers.rb', line 4

def self.format_caller(trace)
  valid_lines = trace.reject { |line| line =~ /fiveruns_tuneup/ }[0,5]
  linked_lines = valid_lines.map { |line| editor_link_line(line) }
  '<pre>%s</pre>' % linked_lines.join("\n")
end

.headObject



17
18
19
20
21
22
# File 'lib/fiveruns/tuneup/panel.rb', line 17

def self.head
  %(
    <script src='#{javascripts_path}/init.js' type='text/javascript'></script>
    <link rel='stylesheet' type='text/css' href='#{stylesheets_path}/tuneup.css'/>
  )
end

.insert_panel(body, run, allow_share = false) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/fiveruns/tuneup/panel.rb', line 9

def self.insert_panel(body, run, allow_share = false)
  return body unless run
  tag = body[/(<body[^>]*>)/i, 1]
  return body unless tag
  panel = Panel.new(run, allow_share)
  body.sub(/<\/head>/i, head << '</head>').sub(tag, tag + panel.to_html)
end

.record(&block) ⇒ Object



8
9
10
11
12
13
# File 'lib/fiveruns/tuneup/step.rb', line 8

def self.record(&block)
  Step.reset!
  root = RootStep.new
  root.record(&block)
  root
end

.step(name, layer, extras = {}, &block) ⇒ Object



15
16
17
18
# File 'lib/fiveruns/tuneup/step.rb', line 15

def self.step(name, layer, extras = {}, &block)
  trace = format_caller(caller)
  Step.new(name, layer, extras.merge('Caller' => trace), nil).record(&block)
end

.strip_root(text) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/fiveruns/tuneup/helpers.rb', line 10

def self.strip_root(text)
  if defined?(::Fiveruns::Tuneup::STRIP_ROOT)
    pattern = /^#{Regexp.quote ::Fiveruns::Tuneup::STRIP_ROOT}\/?/o
    if text =~ pattern
      result = text.sub(pattern, '')
      in_app = result !~ /^gems\//
      return [in_app, result]
    end
  end
  [false, text]
end