Sha256: 0506a76809960d4365edbf06e4855954b76a08bbaa8f4e962dc34ca02fa53dd1

Contents?: true

Size: 765 Bytes

Versions: 1

Compression:

Stored size: 765 Bytes

Contents

require "active_support/core_ext/enumerable"

class Kredis::Types::Proxy
  attr_accessor :redis, :key

  def initialize(redis, key, **options)
    @redis, @key = redis, key
    options.each { |key, value| send("#{key}=", value) }
  end

  def multi(...)
    redis.multi(...)
  end

  def method_missing(method, *args, **kwargs)
    Kredis.logger&.debug log_message(method, *args, **kwargs)
    redis.public_send method, key, *args, **kwargs
  end

  private
    def log_message(method, *args, **kwargs)
      args      = args.flatten.compact_blank.presence
      kwargs    = kwargs.compact_blank.presence
      type_name = self.class.name.split("::").last

      "[Kredis #{type_name}] #{method.upcase} #{key} #{args&.inspect} #{kwargs&.inspect}".chomp
    end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
kredis-0.2.1 lib/kredis/types/proxy.rb