Skip to content

Instantly share code, notes, and snippets.

@kyamaguchi
Created May 30, 2012 01:31
Show Gist options
  • Save kyamaguchi/2832297 to your computer and use it in GitHub Desktop.
Save kyamaguchi/2832297 to your computer and use it in GitHub Desktop.
Capistrano variables
# Ruby 1.8.7
def show_capistrano_variables(exec_proc = false)
report = []
require 'active_support/ordered_hash'
require 'active_support/core_ext/hash/keys'
report << "="*20 + " @variables " + "="*20
ActiveSupport::OrderedHash.new.merge(instance_variable_get("@variables")).stringify_keys.sort.each do |k,v|
next if %w{password}.include?(k)
if v.to_s =~ /^#/
obj = instance_variable_get("@variables")[k.to_sym]
if exec_proc && v.to_s =~ /^#<Proc/
begin
result = obj.class.to_s == 'Proc' ? obj.call : ( obj.class.to_s == 'Array' ? obj.join(',') : obj.to_s )
report << "#{k.to_s.ljust(20)} : #{result.to_s}"
rescue
puts "error [#{k.to_s}], #{$!.message} #{$!.backtrace.first}"
end
end
else
report << "#{k.to_s.ljust(20)} : #{v.to_s}"
end
end
report << "="*20 + " @roles " + "="*20
instance_variable_get("@roles").stringify_keys.sort.each do |k,v|
report << "#{k.to_s.ljust(20)} : #{v.inspect}"
end
puts report.join("\n")
end
desc "Show capistrano variables including proc result"
task :var do
show_capistrano_variables(true)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment