Class: ConsoleUtils::OtherUtils::Shutting
- Inherits:
-
Object
- Object
- ConsoleUtils::OtherUtils::Shutting
- Defined in:
- lib/console_utils/other_utils.rb
Constant Summary collapse
- ENGINES_KEYS_MAP =
{ :rails => "Rails", :record => "ActiveRecord::Base", :controller => "ActionController::Base", :view => "ActionView::Base" }
Class Method Summary collapse
Instance Method Summary collapse
- #call(&block) ⇒ Object
-
#initialize(key, to: Logger::WARN) ⇒ Shutting
constructor
A new instance of Shutting.
-
#with_logger ⇒ Object
Yields engine’s logger for a given key.
Constructor Details
#initialize(key, to: Logger::WARN) ⇒ Shutting
Returns a new instance of Shutting.
39 40 41 42 43 |
# File 'lib/console_utils/other_utils.rb', line 39 def initialize(key, to: Logger::WARN) @key = key @level = to @level = Logger.const_get(@level.upcase) unless @level.is_a?(Numeric) end |
Class Method Details
.call(*args, &block) ⇒ Object
35 36 37 |
# File 'lib/console_utils/other_utils.rb', line 35 def self.call(*args, &block) new(*args).call(&block) end |
Instance Method Details
#call(&block) ⇒ Object
45 46 47 |
# File 'lib/console_utils/other_utils.rb', line 45 def call(&block) with_logger { |logger| logger.silence(@level, &block) } end |
#with_logger ⇒ Object
Yields engine’s logger for a given key.
50 51 52 53 |
# File 'lib/console_utils/other_utils.rb', line 50 def with_logger const_get(ENGINES_KEYS_MAP[@key]). logger.tap { |logger| yield(logger) unless logger.nil? } end |