可变量的作用域在我~/Sites/
目录我有无所不能的Rakefile:Rakefiles:在`load`ed脚本
desc "Run deliver in each directory"
task :deliver do
sh 'for a in $(ls ./*/Rakefile); do (cd $(dirname $a); rake -f Rakefile deliver); done'
end
(以及其他有趣的生产任务,而愚蠢的“默认”的任务,列出了所有任务[见https://github.com/ruby/rake/issues/22])
Sites
中的一些目录中有一个Rakefile。大部分是这样的:
# Rsync options
production_server = 'pacificmedicaltraining.net'
production_user = 'training2'
production_www_dir = 'www'
local_www_dir = 'www'
local_git_dir = 'git'
desc "Run all build and deployment tasks, for continuous delivery"
task :deliver => [:pullgit, :buildjekyll, :pushproduction]
desc "Bring deployed server files local"
task :pullgit do
puts 'Pulling git'
sh "cd '#{local_git_dir}'; git pull"
puts 'Pulled'
end
...
这个Rake文件的行为是由顶部的选项和deliver
任务(其他网站可能不会使用杰奇建筑)完全定义。该文件中的所有其余任务都是复制粘贴。为了DRY的利益,我已将复制粘贴的任务移至~/Sites/common.rake
,并将此文件与load '../common.rake'
一起包含在贡献文件中。
Pulling git rake aborted! NameError: undefined local variable or method 'local_git_dir' for main:Object /Users/williamentriken/Sites/common.rake:4:in 'block in ' Tasks: TOP => pullgit (See full trace by running task with --trace)
如何使该变量可用于load
ed脚本?
你在哪儿叫'load'? – 2015-02-05 21:27:28
该文件中的第一件事 – 2015-02-05 21:51:45