Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capistrano: deploy.rb file refactoring

I have following code in my deploy.rb

namespace :app do
  desc "copies the configuration frile from ~/shared/config/*.yml to ~/config"
  task :copy_config_files,:roles => :app do
    run "cp -fv #{deploy_to}/shared/config/hoptoad.rb #{release_path}/config/initializers"
    run "cp -fv #{deploy_to}/shared/config/app_config.yml #{release_path}/config/app_config.yml"
  end
end

I thought it would be a good idea to keep my deploy.rb file clean and I attempted to move above code to capistrano_utilities.rb under config. I am using Rails application. And I added following line of code to deploy.rb

require File.expand_path(File.dirname(__FILE__) + "/../lib/capistrano_utilities")

Now I am getting following error.

undefined method `namespace' for main:Object (NoMethodError)

The value of self in the deploy.rb is Capistrano::Configuration . While the value of self in capistrano_utilities is Main. So I understand why I am getting namespace method error. What is the fix for this problem?

like image 535
Roger Avatar asked Dec 11 '09 15:12

Roger


1 Answers

In your config/deploy.rb, try load instead of require. Also, capistrano already runs as if you're at the RAILS_ROOT, so there's no need to use __FILE__:

load "lib/capistrano_utilities"

In a capistrano config file, load is redefined to load another configuration file into the current configuration. When passing a path to it, it actually calls load_from_file (a private method defined by capistrano) that just reads the file from disk and instance_eval's it.

like image 81
Ryan McGeary Avatar answered Sep 28 '22 08:09

Ryan McGeary