Top Level Namespace
Defined Under Namespace
Modules: Capistrano, Meataxe
Instance Method Summary collapse
- #host_architecture ⇒ Object
-
#smart_template(from, to = nil) ⇒ Object
First try and copy the file ‘config/deploy/#full_app_name/#from.erb` to `shared/config/#to`.
-
#sub_strings(input_string) ⇒ Object
We often want to refer to variables which are defined in subsequent stage files.
-
#template_file(name) ⇒ Object
Load templates from the local config directory, or fallback to default templates.
- #update_repo(repo_url, target_path) ⇒ Object
Instance Method Details
#host_architecture ⇒ Object
48 49 50 |
# File 'lib/meataxe/capistrano.rb', line 48 def host_architecture capture("uname -m") end |
#smart_template(from, to = nil) ⇒ Object
First try and copy the file ‘config/deploy/#full_app_name/#from.erb` to `shared/config/#to`
If the original source path doesn exist then it will search in: ‘config/deploy/shared/#from.erb` This allows files which are common to all enviros to come from a single source while allowing specific ones to be over-ridden. If the target file name is the same as the source then the second parameter can be left out.
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/meataxe/capistrano.rb', line 12 def smart_template(from, to=nil) to ||= from full_to_path = "#{shared_path}/config/#{to}" if from_erb_path = template_file(from) from_erb = StringIO.new(ERB.new(File.read(from_erb_path)).result(binding)) upload! from_erb, full_to_path info "copying #{from_erb_path} to #{full_to_path}" else error "error #{from} not found" end end |
#sub_strings(input_string) ⇒ Object
We often want to refer to variables which are defined in subsequent stage files. This let’s us use the {var} to represent fetch(:var) in strings which are only evaluated at runtime.
40 41 42 43 44 45 46 |
# File 'lib/meataxe/capistrano.rb', line 40 def sub_strings(input_string) output_string = input_string input_string.scan(/{{(\w*)}}/).each do |var| output_string.gsub!("{{#{var[0]}}}", fetch(var[0].to_sym)) end output_string end |
#template_file(name) ⇒ Object
Load templates from the local config directory, or fallback to default templates.
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/meataxe/capistrano.rb', line 26 def template_file(name) if File.exist?((file = "config/deploy/shared/#{name}.erb")) return file elsif File.exist?((file = "config/deploy/templates/#{name}.erb")) return file elsif File.exist?((file = File.join(File.dirname(__FILE__), "capistrano/templates/#{name}.erb"))) return file end return nil end |
#update_repo(repo_url, target_path) ⇒ Object
52 53 54 55 |
# File 'lib/meataxe/capistrano.rb', line 52 def update_repo(repo_url, target_path) execute "if [ -d #{target_path} ]; then (cd #{target_path} && git pull); else git clone #{repo_url} #{target_path}; fi" #run "cd #{target_path} && if [ -d #{target_path} ]; then (git pull); else (cd #{target_path} && cd.. && git clone #{repo_url} #{target_path}); fi" end |