Sha256: 56cc69ba80263459f90941a46c908bf4d5fd9f1241f99f39d732609380a8dbbb

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 KB

Contents

require 'erb'

module Capistrano
  module SimpleNginx
    module Helpers
      def template template_name
        StringIO.new(template_to_s(template_name))
      end

      def template_to_s template_name
        config_file = File.join(File.dirname(__FILE__), "../../templates/#{template_name}")
        ERB.new(File.read(config_file), nil, '-').result(binding)
      end

      def sudo_upload! from, to
        filename = File.basename(to)
        to_dir = File.dirname(to)
        tmp_file = "/tmp/#{filename}"
        upload! from, tmp_file
        sudo :mv, tmp_file, to_dir
      end

      def file_exists? path
        test "[ -e #{path} ]"
      end

      def deploy_user
        capture :id, '-un'
      end

      def os_is_ubuntu?
        capture(:cat, "/etc/*-release").include? "ubuntu"
      end

      def nginx_config_file
        if os_is_ubuntu?
          "/etc/nginx/sites-available/#{fetch(:nginx_config_name)}.conf"
        else
          "/etc/nginx/conf.d/#{fetch(:nginx_config_name)}.conf"
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
capistrano-simple-nginx-0.0.1 lib/capistrano/simple_nginx/helpers.rb