Skip to content

Commit 04dc1d3

Browse files
committed
moved checking whether the cached collection needs normalizing into normalize_collection
1 parent 1336127 commit 04dc1d3

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

lib/namespaced_env_cache.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,7 @@ def read_collection(name, **opts)
9898
data = @underlying.read(namespaced, **opts)
9999
return nil if data.nil?
100100

101-
if data.is_a?(ActiveRecord::Relation)
102-
data = NamespacedEnvCache.normalize_collection(data)
103-
end
104-
101+
data = NamespacedEnvCache.normalize_collection(data)
105102
type = data.slice!(0)
106103
begin
107104
type.constantize.where(id: data)
@@ -134,10 +131,14 @@ def fetch_collection(name, **opts, &block)
134131
end
135132

136133
# Normalizes a given ActiveRecord collection for use with the cache
137-
# @param value [ActiveRecord::Relation] collection to normalize
134+
# @param value [ActiveRecord::Relation, [String, Integer, Integer, ...]] collection to normalize
138135
# @return [[String, Integer, Integer, ...]]
139136
def self.normalize_collection(value)
140-
[value[0].class.to_s, *value.map(&:id)]
137+
if value.is_a?(ActiveRecord::Relation)
138+
[value[0].class.to_s, *value.map(&:id)]
139+
else
140+
value
141+
end
141142
end
142143

143144
# We have to statically report that we support cache versioning even though this depends on the underlying class.

0 commit comments

Comments
 (0)