From 6ac88832a618f477cc277c48a507ea8e51df01c5 Mon Sep 17 00:00:00 2001 From: Oleg Valter Date: Wed, 15 Jan 2025 17:49:43 +0300 Subject: [PATCH] fixed namespaced_env_cache handling of :include_community default --- lib/namespaced_env_cache.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/namespaced_env_cache.rb b/lib/namespaced_env_cache.rb index c6cbc6874..093c9a90a 100644 --- a/lib/namespaced_env_cache.rb +++ b/lib/namespaced_env_cache.rb @@ -5,10 +5,15 @@ def initialize(underlying) @getters = {} end + def include_community(opts) + include = opts.delete(:include_community) + include.nil? ? true : include + end + # These methods need the cache key name updating before we pass it to the underlying cache. [:decrement, :delete, :exist?, :fetch, :increment, :read, :write, :delete_matched].each do |method| define_method method do |name, *args, **opts, &block| - include_community = opts.delete(:include_community) + include_community = include_community(opts) @underlying.send(method, construct_ns_key(name, include_community: include_community), *args, **opts, &block) end @@ -17,7 +22,7 @@ def initialize(underlying) # These methods need a hash of cache keys updating before we pass it to the underlying cache. [:write_multi].each do |method| define_method method do |hash, *args, **opts, &block| - include_community = opts.delete(:include_community) + include_community = include_community(opts) hash = hash.map { |k, v| [construct_ns_key(k, include_community: include_community), v] }.to_h @underlying.send(method, hash, *args, **opts, &block) end @@ -31,14 +36,14 @@ def initialize(underlying) end def read_multi(*keys, **opts) - include_community = opts.delete(:include_community) + include_community = include_community(opts) keys = keys.map { |k| [construct_ns_key(k, include_community: include_community), k] }.to_h results = @underlying.read_multi(*keys.keys, **opts) results.map { |k, v| [keys[k], v] }.to_h end def fetch_multi(*keys, **opts, &block) - include_community = opts.delete(:include_community) + include_community = include_community(opts) keys = keys.map { |k| construct_ns_key(k, include_community: include_community) } @underlying.fetch_multi(*keys, **opts, &block) end