Class: Yell::Repository

Inherits:
Object
  • Object
show all
Extended by:
MonitorMixin
Includes:
Singleton
Defined in:
lib/yell/repository.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRepository

Returns a new instance of Repository.



14
15
16
# File 'lib/yell/repository.rb', line 14

def initialize
  @loggers = {}
end

Class Method Details

.[](name) ⇒ Yell::Logger

Get loggers from the repository

Examples:

Get the logger

Yell::Repository[ 'development' ]

Returns:

Raises:



35
36
37
# File 'lib/yell/repository.rb', line 35

def self.[]( name )
  synchronize { instance.__fetch__(name) or raise Yell::LoggerNotFound.new(name) }
end

.[]=(name, logger) ⇒ Yell::Logger

Set loggers in the repository

Examples:

Set a logger

Yell::Repository[ 'development' ] = Yell::Logger.new :stdout

Returns:



24
25
26
# File 'lib/yell/repository.rb', line 24

def self.[]=( name, logger )
  synchronize { instance.loggers[name] = logger }
end

.loggersHash

Get the list of all loggers in the repository

Returns:

  • (Hash)

    The map of loggers



42
43
44
# File 'lib/yell/repository.rb', line 42

def self.loggers
  synchronize { instance.loggers }
end

Instance Method Details

#__fetch__(name) ⇒ Object

Fetch the logger by the given name.

If the logger could not be found and has a superclass, it will attempt to look there. This is important for the Yell::Loggable module.



58
59
60
61
62
63
64
65
66
# File 'lib/yell/repository.rb', line 58

def __fetch__( name )
  logger = loggers[name] || loggers[name.to_s]

  if logger.nil? && name.respond_to?(:superclass)
    return __fetch__(name.superclass)
  end

  logger
end

#loggersObject



47
48
49
# File 'lib/yell/repository.rb', line 47

def loggers
  @loggers
end