summaryrefslogtreecommitdiff
path: root/lib/dslkeywords/resource.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/dslkeywords/resource.rb')
-rw-r--r--lib/dslkeywords/resource.rb17
1 files changed, 10 insertions, 7 deletions
diff --git a/lib/dslkeywords/resource.rb b/lib/dslkeywords/resource.rb
index c1c2554..16b34af 100644
--- a/lib/dslkeywords/resource.rb
+++ b/lib/dslkeywords/resource.rb
@@ -1,7 +1,8 @@
-require 'set'
+# frozen_string_literal: true
require_relative 'keyword'
+# rubocop:disable Style/ClassVars
module RCM
# Concern that wraps side-effecting blocks so they are skipped (and
# logged as dry-run) when the --dry option is active. Kept separate
@@ -90,7 +91,6 @@ module RCM
include ResourceDependencies
class NoSuchResourceObject < StandardError; end
- @@resource_find_cache = {}
# Class-level registry: every subclass is registered here when it is
# first loaded (via the inherited hook), so ResourceDependencies can
@@ -107,13 +107,16 @@ module RCM
def self.subclass_names = @@subclass_names.freeze
def self.find(id)
- return @@resource_find_cache[id] if @@resource_find_cache.key?(id)
+ resource_name = id.split(/[( ]/).first.to_sym
+ unless subclass_names.include?(resource_name)
+ raise NameError, "uninitialized constant RCM::#{resource_name.capitalize}"
+ end
- 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 = DSL.object(id)
+ return resource if resource.is_a?(Resource)
- @@resource_find_cache[id] = resource
+ raise NoSuchResourceObject, "Unable to find resource #{id}" if resource.nil?
end
end
end
+# rubocop:enable Style/ClassVars