summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-02-17 00:26:07 +0200
committerPaul Buetow <paul@buetow.org>2025-02-17 00:26:07 +0200
commit9bb314cb170a651571b57767d33b3c01112aa5bc (patch)
tree533b452ae20d567b70bc95d65790002a61253e04
parente13d1a0a7df840bd86e68f6b9604c764c54cc60f (diff)
cache the resource objs
-rw-r--r--lib/dslkeywords/resource.rb6
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/dslkeywords/resource.rb b/lib/dslkeywords/resource.rb
index 11df70e..f646030 100644
--- a/lib/dslkeywords/resource.rb
+++ b/lib/dslkeywords/resource.rb
@@ -69,12 +69,16 @@ module RCM
class NoSuchResourceObject < StandardError; end
+ @@resource_find_cache = {}
+
def self.find(id)
+ return @@resource_find_cache[id] if @@resource_find_cache.key?(id)
+
klass = Object.const_get("RCM::#{id.split('(').first.capitalize}")
resource = ObjectSpace.each_object(klass).find { _1.id == id }
raise NoSuchResourceObject, "Unable to find resource #{id}" if resource.nil?
- resource
+ @@resource_find_cache[id] = resource
end
end
end