summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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