On May 2, 2007, at 9:22 AM, Rob Sanheim wrote:

>
> Sorry, sent that too early.  I'd like:
>
> set :my_func, lambda { # arbitrary ruby code here }
>
> then
>
> task :after_deploy do
>   my_func # this runs the lambda in the context of all servers for
> this task, not locally
> end
>
> The reason I ask for this is because I find myself writing a lot of
> little helper ruby scripts, then pushing them out to all the servers
> so that I can run them from capistrano.  I find ruby much more
> friendly for almost all shell tasks once they go beyond the very
> simple, especially for things like testing if files exist and the
> like.  I really don't like trying to switch my brain into bash mode
> :).
>
> Of course right now, if you just run ruby from w/i a custom task now,
> it just executes in the local scope.
>
> Is something like this possible, maybe using ruby2ruby for sending the
> proc to the servers?
>
> - Rob


        It's probably possible but may be more trouble then it's worth. What  
about something like this instead?

module Ruby
   def ruby(cmd, options={}, &block)
     temp_name = "/tmp/#{Time.now.strftime("%m%d%H%M%S")}" + ".rb"
     begin
       put(cmd, temp_name, :mode => 0700)
       send(run_method, "ruby #{temp_name}", options, &block)
     ensure
       delete temp_name
     end
   end
end

Capistrano.plugin :script, Ruby

task :foo do
    script.ruby "10.times { puts `uname -a` }"
end


Cheers-
-- Ezra Zygmuntowicz 
-- Lead Rails Evangelist
-- [EMAIL PROTECTED]
-- Engine Yard, Serious Rails Hosting
-- (866) 518-YARD (9273)



--~--~---------~--~----~------------~-------~--~----~
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/capistrano
-~----------~----~----~----~------~----~------~--~---

Reply via email to