Browse Source

Merge pull request #10 from andreacampi/COOK-1332

[COOK-1332] Add #release_path and #shared_path convenience methods on the main application resource, so that users don't need to jump through hoops.
Joshua Timberman 12 years ago
parent
commit
05969c2920
3 changed files with 23 additions and 10 deletions
  1. 13 10
      libraries/default.rb
  2. 1 0
      providers/default.rb
  3. 9 0
      resources/default.rb

+ 13 - 10
libraries/default.rb

@@ -71,10 +71,6 @@ class Chef
         end
       end
 
-      def release_path
-        application_provider.release_path
-      end
-
       class OptionsBlock
         include Chef::Resource::Application::OptionsCollector
       end
@@ -135,13 +131,20 @@ class Chef
         klass.extend Chef::Mixin::FromFile
       end
 
-      def release_path
-        if !@deploy_provider
-          #@deploy_provider = Chef::Platform.provider_for_resource(@run_context.resource_collection.find(:deploy_revision => @new_resource.id))
-          @deploy_provider = Chef::Platform.provider_for_resource(@deploy_resource)
-          @deploy_provider.load_current_resource
+      def deploy_provider
+        @deploy_provider ||= begin
+          deploy_provider = Chef::Platform.provider_for_resource(@deploy_resource)
+          deploy_provider.load_current_resource
+          deploy_provider
         end
-        @deploy_provider.release_path
+      end
+
+      def release_path
+        deploy_provider.release_path
+      end
+
+      def shared_path
+        @deploy_resource.shared_path
       end
 
       def callback(what, callback_code=nil)

+ 1 - 0
providers/default.rb

@@ -57,6 +57,7 @@ end
 protected
 
 def before_compile
+  new_resource.application_provider self
   new_resource.sub_resources.each do |resource|
     resource.application_provider self
     resource.run_action :before_compile

+ 9 - 0
resources/default.rb

@@ -51,6 +51,7 @@ attribute :migrate, :kind_of => [TrueClass, FalseClass], :default => false
 attribute :migration_command, :kind_of => [String, NilClass], :default => nil
 attribute :restart_command, :kind_of => [String, NilClass], :default => nil
 attribute :packages, :kind_of => [Array, Hash], :default => []
+attribute :application_provider
 attr_reader :sub_resources
 
 # Callback fires before deploy is started.
@@ -83,6 +84,14 @@ def after_restart(arg=nil, &block)
   set_or_return(:after_restart, arg, :kind_of => [Proc, String])
 end
 
+def release_path
+  application_provider.release_path
+end
+
+def shared_path
+  application_provider.shared_path
+end
+
 def method_missing(name, *args, &block)
   # Build the set of names to check for a valid resource
   lookup_path = ["application_#{name}"]