class CallerWithContext::Caller

Attributes

options[R]

Public Class Methods

new(options={}) click to toggle source
# File lib/caller_with_context/caller.rb, line 8
def initialize(options={})
  @options = {
    colorize: true,
    only_cwd: false,
    lines_of_context: 1
  }.merge(options)
end

Public Instance Methods

format_single_location(location) click to toggle source
# File lib/caller_with_context/caller.rb, line 39
def format_single_location(location)
  output(location.to_s, :light_blue)
  if options[:lines_of_context] > 0
    location.context_lines.each do |line|
      puts line
    end
    puts
  end
end
locations() click to toggle source
# File lib/caller_with_context/caller.rb, line 16
def locations
  return @locations if @locations
  locations = caller_locations
  if @options[:only_cwd]
    locations.select! { |l| l.to_s.include?(Dir.pwd) }
  end
  @locations ||= locations.map { |location| Location.new(location, options[:lines_of_context]) }
end
output(string, color) click to toggle source
# File lib/caller_with_context/caller.rb, line 31
def output(string, color)
  if options[:colorize]
    puts string.send(color)
  else
    puts string
  end
end
show() click to toggle source
# File lib/caller_with_context/caller.rb, line 25
def show
  locations.each do |location|
    format_single_location location
  end
end