Class: Treefell::DebugLogger

Inherits:
Object
  • Object
show all
Defined in:
lib/treefell/debug_logger.rb

Constant Summary collapse

DEFAULT_FILTER_PROC =
proc { true }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(namespace: nil, io: $stdout, color: Color.rotate, filter: nil) ⇒ DebugLogger

Returns a new instance of DebugLogger.



8
9
10
11
12
13
# File 'lib/treefell/debug_logger.rb', line 8

def initialize(namespace: nil, io: $stdout, color: Color.rotate, filter: nil)
  @namespace = namespace
  @io = io
  @color = color
  @filter = filter || DEFAULT_FILTER_PROC
end

Instance Attribute Details

#filterObject (readonly)

Returns the value of attribute filter.



6
7
8
# File 'lib/treefell/debug_logger.rb', line 6

def filter
  @filter
end

#ioObject (readonly)

Returns the value of attribute io.



6
7
8
# File 'lib/treefell/debug_logger.rb', line 6

def io
  @io
end

#namespaceObject (readonly)

Returns the value of attribute namespace.



6
7
8
# File 'lib/treefell/debug_logger.rb', line 6

def namespace
  @namespace
end

Instance Method Details

#==(other) ⇒ Object



27
28
29
30
31
32
# File 'lib/treefell/debug_logger.rb', line 27

def ==(other)
  other.is_a?(self.class) &&
    other.namespace == namespace &&
    other.io == io &&
    other.filter == filter
end

#puts(message) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/treefell/debug_logger.rb', line 15

def puts(message)
  if @filter.call(namespace, message)
    formatted_namespace = if namespace
      @color.colorize(namespace)
    end
    @io.puts [
      formatted_namespace,
      message
    ].compact.join(' ')
  end
end