On Nov 16, 2011, at 1:15 AM, Donovan Bray wrote: > I'm not sure why you need to use a lambda then force it to memoize the > return. > > Why doesn't this work for you? > > set(:user) {Capistrano::CLI.ui.ask("Your SSH User name : ")} > > on first use it will ask; then return the same value every time it's used > thereafter ---- Lee suggested using a lambda and I was running with it but alas, it doesn't seem to have any impact on my problem.
I am gathering now that my problem is that each 'fork' of a new cap process will have its own variables so even though it's all contained in a single 'deploy' file, the separate processes each have their own environment and perhaps the only way around it is to create a local 'settings' file (possibly at the start of each run and nuke it at the end). Perhaps I should restate the problem... I have various namespaces & tasks in one deploy.rb namespace 'deploy' do task :tag do end task :code do system "cap #{stage} i18n:tag deploy" end task :i18n do system "cap #{stage} i18n:tag deploy" end ... end namespace 'code' do ... end namespace 'i18n' do ... end > > And on scoping global variables. That's method_missing at work not variable > scoping. > > If you create a local variable of the same name as a capistrano config > variable, ruby will use that local variable. But if there is no local > variable of the same name ruby tries method_missing defined on the instance; > and you are in an instance of Capistrano::Configuration when defining tasks; > which then attempts to find a matching config variable and returns that if > found. If not ruby keeps walking up the class inheritance tree until it > finally tries Object#method_missing if that fails then you finally get a no > method error > > You can still get at a config value if you've defined a local variable of the > same name. > > set :user, 'foo' > > p user # => foo > > begin > user = 'bar' > p user # => bar > p fetch(:user) # => foo > end > > p user # => foo > > > > On Nov 15, 2011, at 2:54 PM, Craig White <craig.wh...@ttiltd.com> wrote: > >> On Nov 15, 2011, at 1:42 PM, Craig White wrote: >> >>> >>> On Nov 15, 2011, at 10:56 AM, Lee Hambley wrote: >>> >>>> I meant, by "written long form" that it wasn't valid syntax… but it was >>>> supposed to be easier to understand: >>>> >>>> set(:branch, lambda { .... }) >>>> >>>> is the required way... >>> ---- >>> something about capistrano makes global variables local and makes me >>> crazy... >>> >>> set(:user, lambda do >>> if $my_user == nil then >>> $my_user = Capistrano::CLI.ui.ask("Your SSH User name : ") >>> else >>> $my_user >>> end >>> end) >>> >>> and if any 'task' has multiple deploys or invoked before/after tasks that >>> call :user a second time, I am still asked for the user name a second time. >> ---- >> same result as a one-liner too... ;-( >> >> set(:user, lambda { $my_user == nil ? $my_user = >> Capistrano::CLI.ui.ask("Your SSH User name : ") : $my_user } ) >> >> Craig >> >> -- >> * You received this message because you are subscribed to the Google Groups >> "Capistrano" group. >> * To post to this group, send email to capistrano@googlegroups.com >> * To unsubscribe from this group, send email to >> capistrano+unsubscr...@googlegroups.com For more options, visit this group >> at http://groups.google.com/group/capistrano?hl=en > > -- > * You received this message because you are subscribed to the Google Groups > "Capistrano" group. > * To post to this group, send email to capistrano@googlegroups.com > * To unsubscribe from this group, send email to > capistrano+unsubscr...@googlegroups.com For more options, visit this group at > http://groups.google.com/group/capistrano?hl=en -- Craig White ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ craig.wh...@ttiltd.com 1.800.869.6908 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ www.ttiassessments.com Need help communicating between generations at work to achieve your desired success? Let us help! -- * You received this message because you are subscribed to the Google Groups "Capistrano" group. * To post to this group, send email to capistrano@googlegroups.com * To unsubscribe from this group, send email to capistrano+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/capistrano?hl=en