Module: Rubeus::Verboseable

Included in:
ComponentLoader, Extensions
Defined in:
lib/rubeus/verboseable.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.outObject



4
5
6
# File 'lib/rubeus/verboseable.rb', line 4

def out
  @out || $stderr
end

.out=(value) ⇒ Object



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

def out=(value)
  @out = value
end

Instance Method Details

#log_if_verbose(*messages) ⇒ Object



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
# File 'lib/rubeus/verboseable.rb', line 13

def log_if_verbose(*messages)
  return(block_given? ? yield : nil) unless self.verbose
  name = is_a?(Module) ? self.name : self.class.name
  msg = "#{name} %s" %
    messages.map{|m| m.is_a?(Exception) ? ("#{m.to_s}\n%s" % m.backtrace.join("\n  ")) : m }.
    join("\n")
  @@indent ||= 0
  if @@indent > 0
    msg.gsub!(/^/, '  ' * @@indent)
  end
  if block_given?
    indent_backup = @@indent
    @@indent += 1
    Verboseable.out.puts("#{msg} {")
    begin
      return yield
    rescue Exception => err
      Verboseable.out.puts("#{'  ' * @@indent} RAISED: #{err.inspect}")
      raise
    ensure
      @@indent = indent_backup
      Verboseable.out.puts("#{'  ' * @@indent}}")
    end
  else
    Verboseable.out.puts(msg)
  end
end