Module: LogBuddy::Utils

Included in:
LogBuddy
Defined in:
lib/log_buddy/utils.rb

Instance Method Summary collapse

Instance Method Details

#arg_and_blk_debug(arg, blk) ⇒ Object



11
12
13
14
15
# File 'lib/log_buddy/utils.rb', line 11

def arg_and_blk_debug(arg, blk)
  result = eval(arg, blk.binding)
  result_str = obj_to_string(result, :quote_strings => true)
  LogBuddy.debug(%[#{arg} = #{result_str}\n])
end

#debug(obj) ⇒ Object



4
5
6
7
8
9
# File 'lib/log_buddy/utils.rb', line 4

def debug(obj)
  return if @disabled
  str = obj_to_string(obj)
  stdout_puts(str) if log_to_stdout?
  logger.debug(str)
end

#obj_to_string(obj, options = {}) ⇒ Object



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

def obj_to_string(obj, options = {})
  quote_strings = options.delete(:quote_strings)
  case obj
  when ::String
    quote_strings ? %["#{obj}"] : obj
  when ::Exception
    "#{ obj.message } (#{ obj.class })\n" <<
      (obj.backtrace || []).join("\n")
  else
    LogBuddy.use_awesome_print? && obj.respond_to?(:ai) ?
      obj.ai : obj.inspect
  end
end

#parse_args(logged_line) ⇒ Object

Returns array of arguments in the block You must use the brace form (ie d { “hi” }) and not do…end



23
24
25
26
# File 'lib/log_buddy/utils.rb', line 23

def parse_args(logged_line)
  block_contents = logged_line[/\{(.*?)\}/, 1]
  args = block_contents ? block_contents.split(";").map {|arg| arg.strip } : []
end

#read_line(frame) ⇒ Object

Return the calling line



29
30
31
32
33
34
35
# File 'lib/log_buddy/utils.rb', line 29

def read_line(frame)
  file, line_number = frame.split(/:/, 2)
  line_number = line_number.to_i
  lines = File.readlines(file)

  lines[line_number - 1]
end

#stdout_puts(str) ⇒ Object



17
18
19
# File 'lib/log_buddy/utils.rb', line 17

def stdout_puts(str)
  puts str
end