不要在Capistrano 3中重复自己

时间:2014-11-02 18:45:08

标签: ruby-on-rails capistrano capistrano3

我当前的命名空间如下所示:

namespace :deploy do
  task :npm_install do
    on roles :all do
      within release_path do
        execute :npm, :install
      end
    end
  end

  task :bower_install do
    on roles :all do
      within release_path do
        execute './node_modules/.bin/bower', :install
      end
    end
  end

  task :build do
    on roles :all do
      within release_path do
        invoke 'deploy:npm_install'
        invoke 'deploy:bower_install'
      end
    end
  end

  after :finishing,  :build
end

我想知道是否有另一种方法可以避免重复和嵌套rolesrelease_path的阻止。

我怎样才能更简洁地写出来?

1 个答案:

答案 0 :(得分:1)

我相信你写它的方式是Capistrano的标准。例如,官方Rails任务以相同的方式执行:https://github.com/capistrano/rails/blob/master/lib/capistrano/tasks/assets.rake

<html>
<head>
    <title>Cron</title>
</head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<body>
<h1>Cron page</h1>
<script type="text/javascript">
    setInterval(function(){
        $.get('http://localhost/test/test.php', function(data) {
            console.log(data);
         });
    }, 5000);
</script>
</body>
</html>