Class: Librarian::Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/librarian/logger.rb

Constant Summary collapse

LIBRARIAN_PATH =
librarian_path

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(environment) ⇒ Logger

Returns a new instance of Logger.



11
12
13
# File 'lib/librarian/logger.rb', line 11

def initialize(environment)
  self.environment = environment
end

Instance Attribute Details

#environmentObject

Returns the value of attribute environment.



8
9
10
# File 'lib/librarian/logger.rb', line 8

def environment
  @environment
end

Instance Method Details

#debug(string = nil, &block) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/librarian/logger.rb', line 21

def debug(string = nil, &block)
  return unless ui

  if ui.respond_to?(:debug_line_numbers) && ui.debug_line_numbers
    loc = caller.find{|l| !(l =~ /in `debug'$/)}
    if loc =~ /^(.+):(\d+):in `(.+)'$/
      loc = "#{Pathname.new($1).relative_path_from(LIBRARIAN_PATH)}:#{$2}:in `#{$3}'"
    end
    ui.debug { "[Librarian] #{string || yield} [#{loc}]" }
  else
    ui.debug { "[Librarian] #{string || yield}" }
  end
end

#info(string = nil, &block) ⇒ Object



15
16
17
18
19
# File 'lib/librarian/logger.rb', line 15

def info(string = nil, &block)
  return unless ui

  ui.info(string || yield)
end

#relative_path_to(path) ⇒ Object



35
36
37
# File 'lib/librarian/logger.rb', line 35

def relative_path_to(path)
  environment.project_relative_path_to(path)
end