-S confuses me

57 views
Skip to first unread message

jeroen

unread,
Dec 20, 2006, 4:36:46 AM12/20/06
to Capistrano
Hi,

Suppose I have this in my deploy.rb

if defined? stage
puts "ja"
else
puts "nee"
end
puts stage

cap deploy -S stage=123
output:
nee
123

cap deploy
output:
nee


c:/ruby/lib/ruby/gems/1.8/gems/capistrano-1.2.0/lib/capistrano/configuration.rb:239:in
`method_missing': undefined local variable or method
`stage' for #<Capistrano::Configuration:0x2c83500> (NameError)
from ./config/deploy.rb:21:in `load'

-------------

I'm confused because both cases print "nee" but in the first case the
value of stage (123) is printed, so it must be defined.

On possible way to deal with it is wrap it in inside a begin/rescue
clause and check for a NameError but that's kinda ugly.

Can somebody explain why defined? doesn't work?

TIA

Jeroen

Sean Cribbs

unread,
Dec 20, 2006, 8:44:38 AM12/20/06
to capis...@googlegroups.com
I believe defined? is only for constants.  If it's a locally-defined variable, it will either have a value or be nil (unassigned).  Try this:

if stage

  puts "ja"
else
  puts "nee"
end
puts stage

Sean Cribbs
seancribbs.com

On 12/20/06, jeroen < jer...@supercool.nl> wrote:

Hi,

Suppose I have this in my deploy.rb

if defined? stage
  puts "ja"
else
  puts "nee"
end
puts stage

cap deploy -S stage=123
  output:
    nee
    123

cap deploy
  output:
   nee


c:/ruby/lib/ruby/gems/1.8/gems/capistrano- 1.2.0/lib/capistrano/configuration.rb:239:in

Jamis Buck

unread,
Dec 20, 2006, 10:07:09 AM12/20/06
to capis...@googlegroups.com
Capistrano variables are not really "variables". They use
method_missing to find them, so defined? won't work.

If you want to know if a variable has been set (using -S, -s, or set
()), you have to do something like this:

if variables.include?(:stage)
...
else
...
end

- Jamis

Reply all
Reply to author
Forward
0 new messages