-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
144 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# frozen_string_literal: true | ||
|
||
# @api private | ||
# @since 0.3.0 | ||
module AnyCache::Delegation | ||
class << self | ||
# @param base_klass [Class] | ||
# @return [void] | ||
# | ||
# @api private | ||
# @since 0.2.0 | ||
def included(base_klass) | ||
base_klass.extend(ClassMethods) | ||
end | ||
end | ||
|
||
# @api private | ||
# @since 0.3.0 | ||
module ClassMethods | ||
# @param receiver [Symbol, String] | ||
# @param delegators [Array<Symbol, String>] | ||
# @return [void] | ||
# | ||
# @api private | ||
# @since 0.3.0 | ||
def def_loggable_delegators(receiver, *delegators) | ||
delegators.each { |delegat| def_loggable_delegator(receiver, delegat) } | ||
end | ||
|
||
# @param receiver [Symbol, String] | ||
# @param delegator [Symbol, String] | ||
# @return [void] | ||
# | ||
# @api private | ||
# @since 0.3.0 | ||
def def_loggable_delegator(receiver, delegat) | ||
define_method(delegat) do |*args, **opts, &block| | ||
send(receiver).send(delegat, *args, **opts, &block).tap do | ||
shared_config[:logger].tap do |logger| | ||
AnyCache::Logging::Activity.log( | ||
self, logger, activity: delegat, message: <<~MESSAGE | ||
performed <##{delegat}> operation with params: #{args} and options: #{opts}. | ||
MESSAGE | ||
) if logger | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# frozen_string_literal: true | ||
|
||
module AnyCache::Logging | ||
# @api private | ||
# @since 0.3.0 | ||
class Logger < ::Logger | ||
# @api private | ||
# @since 0.3.0 | ||
def initialize(*, **) | ||
super | ||
self.level = ::Logger::INFO | ||
end | ||
end | ||
|
||
# @api private | ||
# @since 0.3.0 | ||
module Activity | ||
# @return [String] | ||
# | ||
# @api private | ||
# @since 0.3.0 | ||
ANONYMOUS_CACHER_INSTANCE_NAME = '<anonymous_cache>' | ||
|
||
class << self | ||
# @param cacher [AnyCache] | ||
# @param logger [::Logger] | ||
# @option activity [String, NilClass] | ||
# @param message [String, NillClass] | ||
# @return [void] | ||
# | ||
# @api private | ||
# @since 0.3.0 | ||
def log(cacher, logger, activity: nil, message: nil) | ||
cacher = cacher.class.name || ANONYMOUS_CACHER_INSTANCE_NAME | ||
progname = "[AnyCache<#{cacher}>/Activity<#{activity}>]" | ||
logger.add(logger.level, message, progname) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
describe 'Logging' do | ||
# TODO | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
module SpecSupport::NullLogger | ||
class << self | ||
def method_missing(method_name, *arguments, &block) | ||
nil | ||
end | ||
|
||
def respond_to_missing?(method_name, *arguments, &block) | ||
true | ||
end | ||
end | ||
end |