Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow logger to be lazy and converted on first use #14

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions lib/brpoplpush/redis_script/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ module RedisScript
#
# @author Mikael Henriksson <[email protected]>
class Config
#
# @!attribute [r] logger
# @return [Logger] a logger to use for debugging
attr_reader :logger
#
# @!attribute [r] scripts_path
# @return [Pathname] a directory with lua scripts
Expand Down Expand Up @@ -49,17 +45,23 @@ def scripts_path=(obj)
end
end

def logger
# Convert to a regular logger on first call
@logger = @logger.call if @logger.is_a?(Proc)
@logger
end

#
# Sets a value for logger
#
# @param [Logger] obj a logger to use
# @param [Logger, Proc] obj a logger to use
#
# @raise [ArgumentError] when given argument isn't a Logger
#
# @return [Logger]
#
def logger=(obj)
raise ArgumentError, "#{obj} should be a Logger" unless obj.is_a?(Logger)
raise ArgumentError, "#{obj} should be a Logger or a proc" unless obj.is_a?(Logger) || obj.is_a?(Proc)

@logger = obj
end
Expand Down