Class: PerfCheck

Inherits:
Object
  • Object
show all
Defined in:
lib/perf_check.rb,
lib/perf_check/git.rb,
lib/perf_check/server.rb,
lib/perf_check/railtie.rb,
lib/perf_check/test_case.rb

Defined Under Namespace

Classes: Git, Railtie, Server, TestCase

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePerfCheck

Returns a new instance of PerfCheck.



27
28
29
30
31
# File 'lib/perf_check.rb', line 27

def initialize
  self.options = OpenStruct.new
  self.server = Server.new
  self.test_cases = []
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



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

def options
  @options
end

#serverObject

Returns the value of attribute server.



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

def server
  @server
end

#test_casesObject

Returns the value of attribute test_cases.



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

def test_cases
  @test_cases
end

Class Method Details

.app_rootObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/perf_check.rb', line 12

def self.app_root
  @app_root ||= begin
    dir = Dir.pwd
    until dir == '/' || File.exist?("#{dir}/config/application.rb")
      dir = File.dirname(dir)
    end

    unless File.exist?("#{dir}/config/application.rb")
      abort("perf_check should be run from a rails directory")
    end

    dir
  end
end

Instance Method Details

#add_test_case(route) ⇒ Object



33
34
35
# File 'lib/perf_check.rb', line 33

def add_test_case(route)
  test_cases.push(TestCase.new(route.sub(/^([^\/])/, '/\1')))
end

#runObject



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/perf_check.rb', line 37

def run
  trigger_before_start_callbacks

  profile_requests

  if options.reference
    Git.stash_if_needed
    Git.checkout_reference(options.reference)
    test_cases.each{ |x| x.switch_to_reference_context }

    profile_requests
  end
end