Module: Capistrano::Passenger5Nginx::Helpers
- Defined in:
- lib/capistrano/passenger5_nginx/helpers.rb
Defined Under Namespace
Classes: ERBNamespace
Instance Method Summary collapse
- #deploy_user ⇒ Object
- #file_exists?(path) ⇒ Boolean
- #sudo_upload!(from, to) ⇒ Object
-
#template(template_name, locals = {}) ⇒ Object
renders the ERB template specified by template_name to a StringIO buffer.
-
#template_to_s(template_name, locals = {}) ⇒ Object
renders the ERB template specified by template_name to string.
Instance Method Details
#deploy_user ⇒ Object
28 29 30 |
# File 'lib/capistrano/passenger5_nginx/helpers.rb', line 28 def deploy_user capture :id, '-un' end |
#file_exists?(path) ⇒ Boolean
24 25 26 |
# File 'lib/capistrano/passenger5_nginx/helpers.rb', line 24 def file_exists?(path) test "[ -e #{path} ]" end |
#sudo_upload!(from, to) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/capistrano/passenger5_nginx/helpers.rb', line 32 def sudo_upload!(from, to) filename = File.basename(to) to_dir = File.dirname(to) tmp_file = "#{fetch(:tmp_dir)}/#{filename}" upload! from, tmp_file sudo :mv, tmp_file, to_dir end |
#template(template_name, locals = {}) ⇒ Object
renders the ERB template specified by template_name to a StringIO buffer
20 21 22 |
# File 'lib/capistrano/passenger5_nginx/helpers.rb', line 20 def template(template_name, locals = {}) StringIO.new(template_to_s(template_name, locals)) end |
#template_to_s(template_name, locals = {}) ⇒ Object
renders the ERB template specified by template_name to string. Use the locals variable to pass locals to the ERB template
9 10 11 12 13 14 15 16 17 |
# File 'lib/capistrano/passenger5_nginx/helpers.rb', line 9 def template_to_s(template_name, locals = {}) config_file = "#{fetch(:templates_path)}/#{template_name}" # if no customized file, proceed with default unless File.exists?(config_file) config_file = File.join(File.dirname(__FILE__), "../../generators/capistrano/passenger5_nginx/templates/#{template_name}") end ERB.new(File.read(config_file)).result(ERBNamespace.new(locals).get_binding) end |