/
.irbrc
73 lines (61 loc) · 2.19 KB
/
.irbrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
if defined? Rails
puts 'This should only run in rails console!'
def routes
# (@route_set ||= ActionDispatch::Routing::RouteSet.new)
(@route_set ||= begin
obj = Object.new
obj.extend Rails.application.routes.url_helpers
obj
end).methods.grep /path/
end
$LOAD_PATH << '$HOME/.rvm/gems/ruby-2.3.1/gems/colorize-0.7.7/lib'
$LOAD_PATH << '$HOME/code/httplog/lib/'
# default_url_options[:host] = 'localhost'
if Rails.env.test?
puts 'Use the `migration` variable to access ActiveRecord::Migration methods, such as those available in db/migrate'
class << self
def migration
ActiveRecord::Migration
end
end
require 'factory_girl'
FactoryGirl.find_definitions
end
# require 'hirb'
# Hirb.enable
# the following code just sets up rspec_profiling if it works
results.connection if defined?(results) && results.respond_to?(:connection)
# require "awesome_print"
require 'objspace'
# require 'irbtools'
# require 'sidekiq/testing/inline'
if defined?(ActiveRecordQueryTrace)
ActiveRecordQueryTrace.enabled = true
# ActiveRecordQueryTrace.colorize = true
ActiveRecordQueryTrace.lines = 10
end
end
# taken from http://dalibornasevic.com/posts/51-tracing-ruby-code (a bit improved upon)
def trace(filename = '/tmp/trace', event_types = [:call, :return], *matchers)
points = []
tracer = TracePoint.new(*event_types) do |trace_point|
if matchers.all? { |match| trace_point.path.match(match) }
points << { event: trace_point.event,
file: trace_point.path, line: trace_point.lineno,
class: trace_point.defined_class,
method: trace_point.method_id }.merge(
trace_point.event == :return ? { return: trace_point.return_value } : {}
)
end
end
result = tracer.enable { yield }
File.open("#{filename}.rb_trace", 'w') do |file|
points.each do |point|
event_prefix = point[:event] == :return ? 'return' : 'call'
return_value = point[:return] ? "(#{point[:return]})" : ''
file.puts "#{point[:file]}:#{point[:line]}:#{event_prefix} #{point[:class]}##{point[:method]} #{return_value}"
end
end
result
end
require "tracer"