Browse Source

Merge branch 'COOK-2537'

jtimberman 11 years ago
parent
commit
77460f015a
1 changed files with 37 additions and 0 deletions
  1. 37 0
      resources/default.rb

+ 37 - 0
resources/default.rb

@@ -128,6 +128,43 @@ def method_missing(name, *args, &block)
   resource
 end
 
+def do_i_respond_to?(*args)
+  name = args.first.to_s
+  # Build the set of names to check for a valid resource
+  lookup_path = ["application_#{name}"]
+  run_context.cookbook_collection.each do |cookbook_name, cookbook_ver|
+    if cookbook_name.start_with?("application_")
+      lookup_path << "#{cookbook_name}_#{name}"
+    end
+  end
+  lookup_path << name
+  found = false
+  # Try to find our resource
+  lookup_path.each do |resource_name|
+    begin
+      Chef::Log.debug "Looking for application resource #{resource_name} for #{name}"
+      Chef::Resource.resource_for_node(resource_name.to_sym, node)
+      found = true
+      break
+    rescue NameError => e
+      # Keep calm and carry on
+    end
+  end
+  found
+end
+
+# If we are using a current version of ruby, use respond_to_missing?
+# instead of respond_to? so we provide proper behavior
+if(Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('1.9.1'))
+  def respond_to_missing?(*args)
+    super || do_i_respond_to?(*args)
+  end
+else
+  def respond_to?(*args)
+    super || do_i_respond_to?(*args)
+  end
+end
+
 def to_ary
   nil
 end