Module: LogRequire

Defined in:
lib/log_require.rb,
lib/log_require/flat.rb,
lib/log_require/node.rb,
lib/log_require/graph.rb

Defined Under Namespace

Modules: Flat, Graph Classes: Node

Class Method Summary collapse

Class Method Details

.clean_caller(c) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/log_require.rb', line 42

def self.clean_caller(c)
  if c =~ %r{ruby-[\d.]+/gems/(.*):(\d+):in `.*$} ||
     c =~ %r{(ruby-[\d.]+/lib/ruby/[\d.]+/.*):(\d+):in `.*$} ||
     c =~ %r{(ruby/site_ruby/[\d.]+/.*):(\d+):in `.*$} ||
     c =~ %r{^(.*?):(\d+):in `.*$} then

     return [$1, $2]
  end
end

.file?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/log_require.rb', line 12

def self.file?
  !ENV["LOG_REQUIRE"].nil?
end

.find_caller(arr, c) ⇒ Object



52
53
54
55
56
57
58
59
# File 'lib/log_require.rb', line 52

def self.find_caller(arr, c)
  arr.each do |s|
    if s =~ /#{c}:\d+:in/ then
      return true
    end
  end
  false
end

.graph?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/log_require.rb', line 8

def self.graph?
  !ENV["LOG_REQUIRE_GRAPH"].nil?
end

.setupObject



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
# File 'lib/log_require.rb', line 16

def self.setup
  io = if file? then
    File.open(ENV["LOG_REQUIRE"], 'w')
  else
    STDERR
  end

  if graph? then
    $log_require_stack = []
    $log_require_frame = Node.root
    Kernel.include(LogRequire::Graph)
    at_exit do
      io.puts
      io.puts LogRequire::Node.root.to_graph_s()
      LogRequire::Node.root.print_children(io)
    end

  else
    $log_require = io
    if file? then
      io.puts "require name,caller,line number"
    end
    Kernel.include(LogRequire::Flat)
  end
end