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.



16
17
18
# File 'lib/yell/repository.rb', line 16

def initialize
  @loggers = {}
end

Class Method Details

.[](name) ⇒ Yell::Logger

Get loggers from the repository

Examples:

Get the logger

Yell::Repository[ 'development' ]

Returns:

Raises:



37
38
39
# File 'lib/yell/repository.rb', line 37

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:



26
27
28
# File 'lib/yell/repository.rb', line 26

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



44
45
46
# File 'lib/yell/repository.rb', line 44

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.



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

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



49
50
51
# File 'lib/yell/repository.rb', line 49

def loggers
  @loggers
end