Module: Callsite

Defined in:
lib/callsite.rb,
lib/callsite/version.rb

Defined Under Namespace

Modules: FileMethods, LoadPathMethods, ModuleMethods, StringMethods Classes: Line

Constant Summary collapse

UnparsableCallLine =
Class.new(RuntimeError)
VERSION =
'0.0.11'

Class Method Summary collapse

Class Method Details

.__DIR_REL__(called_from = nil) ⇒ Object



7
8
9
10
11
12
# File 'lib/callsite.rb', line 7

def self.__DIR_REL__(called_from = nil)
  called_from ||= caller.first
  caller_path = parse(called_from).filename
  caller_path = '.' if caller_path == ''
  File.expand_path(File.dirname(caller_path))
end

.activate_allObject



59
60
61
62
63
64
65
66
# File 'lib/callsite.rb', line 59

def self.activate_all
  activate_string_methods
  activate_file_methods
  activate_module_methods
  activate_kernel_dir_methods
  activate_kernel_require_methods
  activate_loadpath_methods
end

.activate_file_methodsObject



35
36
37
38
# File 'lib/callsite.rb', line 35

def self.activate_file_methods
  activate_kernel_dir_methods
  ::File.send(:extend, FileMethods)
end

.activate_kernel_dir_methodsObject



45
46
47
# File 'lib/callsite.rb', line 45

def self.activate_kernel_dir_methods
  require 'loaders/kernel_dir'
end

.activate_kernel_require_methodsObject



49
50
51
52
# File 'lib/callsite.rb', line 49

def self.activate_kernel_require_methods
  activate_loadpath_methods
  require 'loaders/kernel_require'
end

.activate_loadpath_methodsObject



54
55
56
57
# File 'lib/callsite.rb', line 54

def self.activate_loadpath_methods
  activate_kernel_dir_methods
  require 'loaders/load_path'
end

.activate_module_methodsObject



40
41
42
43
# File 'lib/callsite.rb', line 40

def self.activate_module_methods
  activate_kernel_dir_methods
  ::Module.send(:include, ModuleMethods)
end

.activate_string_methodsObject



30
31
32
33
# File 'lib/callsite.rb', line 30

def self.activate_string_methods
  activate_kernel_dir_methods
  ::String.send(:include, StringMethods)
end

.parse(input) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/callsite.rb', line 14

def self.parse(input)
  if input.respond_to?(:backtrace)
    parse(input.backtrace)
  elsif input.is_a?(Array)
    block_given? ?
      input.each{|line| yield parse(line)} :
      input.map{|line| parse(line)}
  else
    if match = input.match(/^(.*?)(:(\d+))(:in `(.*)')?$/)
      Line.new(match[1], match[3].to_i, match[5])
    else
      raise UnparsableCallLine.new("unable to parse #{input}")
    end
  end
end