Module: DebugLogging::ArgumentPrinter

Defined in:
lib/debug_logging/argument_printer.rb

Instance Method Summary collapse

Instance Method Details

#debug_arguments_to_s(args: nil, config_proxy: nil) ⇒ Object



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
# File 'lib/debug_logging/argument_printer.rb', line 3

def debug_arguments_to_s(args: nil, config_proxy: nil)
  printed_args = ""
  add_args_ellipsis = false
  if config_proxy.debug_last_hash_to_s_proc && args[-1].is_a?(Hash)
    if args.length > 1
      add_last_hash_ellipsis = false
      if config_proxy.debug_multiple_last_hashes
        last_hash_args, other_args = args.partition do |arg|
                                        arg.is_a?(Hash)
                                      end
        other_args_string = other_args.map(&:inspect).join(", ").tap {|x| add_args_ellipsis = x.length > config_proxy.debug_args_max_length}[0..(config_proxy.debug_args_max_length)]
        last_hash_args_string = last_hash_args.map do |arg|
                                  String(config_proxy.
                                      debug_last_hash_to_s_proc.
                                      call(arg)).
                                      tap {|x|
                                            add_last_hash_ellipsis = x.length > config_proxy.debug_last_hash_max_length
                                          }[0..(config_proxy.debug_last_hash_max_length)].
                                      tap {|x|
                                            x << config_proxy.debug_ellipsis if add_last_hash_ellipsis
                                          }
                                end.join(", ")
        printed_args << other_args_string if other_args_string
        printed_args << ", " if !other_args_string.empty? && !last_hash_args_string.empty?
        printed_args << last_hash_args_string if last_hash_args_string
      else
        printed_args << args[0..(-2)].map {|x| x.inspect}.join(", ").tap {|x| add_args_ellipsis = x.length > config_proxy.debug_args_max_length}[0..(config_proxy.debug_args_max_length)]
        printed_args << config_proxy.debug_ellipsis if add_args_ellipsis
        printed_args << ", " << config_proxy.debug_last_hash_to_s_proc.call(args[-1]).tap {|x| add_last_hash_ellipsis = x.length > config_proxy.debug_last_hash_max_length}[0..(config_proxy.debug_last_hash_max_length)]
        printed_args << config_proxy.debug_ellipsis if add_last_hash_ellipsis
      end
    else
      printed_args << String(config_proxy.debug_last_hash_to_s_proc.call(args[0])).tap {|x| add_last_hash_ellipsis = x.length > config_proxy.debug_last_hash_max_length}[0..(config_proxy.debug_last_hash_max_length)]
      printed_args << config_proxy.debug_ellipsis if add_last_hash_ellipsis
    end
  else
    if args.length == 1 && args[0].is_a?(Hash)
      # handle double splat
      printed_args << ("**" << args.map {|x| x.inspect}.join(", ").tap {|x| add_args_ellipsis = x.length > config_proxy.debug_args_max_length})[0..(config_proxy.debug_args_max_length)]
    else
      printed_args << args.map {|x| x.inspect}.join(", ").tap {|x| add_args_ellipsis = x.length > config_proxy.debug_args_max_length}[0..(config_proxy.debug_args_max_length)]
    end
    printed_args << config_proxy.debug_ellipsis if add_args_ellipsis
  end
  "(#{printed_args})"
end