Sha256: f3ae5b1b3b2ea66c8857b73da64241787936a7858f01c17ba0a269e9cf44bf83

Contents?: true

Size: 1.27 KB

Versions: 1

Compression:

Stored size: 1.27 KB

Contents

require 'rake/clean'
require 'rake/tasklib'

module Rake::Funnel::Tasks
  class MSDeploy < Rake::TaskLib
    include Rake::Funnel::Support
    include Rake::Funnel::Support::MSDeploy

    attr_accessor :name, :msdeploy, :log_file, :args

    def initialize(name = :msdeploy)
      @name = name
      @msdeploy = 'msdeploy'
      @args = {}

      yield self if block_given?
      define
    end

    def log_file
      @log_file || "#{@name}.log"
    end

    private
    def define
      CLEAN.include(log_file)

      desc "Deploy #{deploy_source(args)}"
      task @name do
        mapper = Mapper.new(:MSDeploy)
        cmd = [quote(msdeploy), mapper.map(args)]
          .flatten
          .join(' ')

        RegistryPatch.new do
          shell(cmd, log_file: log_file, error_lines: /^(error|[\w\.]*exception)/i)
        end
      end

      self
    end

    def deploy_source(args)
      source = (args || {}).fetch(:source, {})
      path = source.first
      return if path.nil?

      Pathname.new(path[1]).relative_path_from(Pathname.new('.').realpath) rescue path[1]
    end

    def quote(value)
      value = value.gsub(/"/, '""') if value.kind_of?(String)
      return %Q{"#{value}"} if value =~ /\s/
      value
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rake-funnel-0.1.0.pre lib/rake/funnel/tasks/msdeploy.rb