lib/rake/funnel/tasks/msdeploy.rb in rake-funnel-0.1.0.pre vs lib/rake/funnel/tasks/msdeploy.rb in rake-funnel-0.2.0.pre

- old
+ new

@@ -1,52 +1,45 @@ -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 + attr_accessor :name, :msdeploy, :args, :log_file - def initialize(name = :msdeploy) - @name = name - @msdeploy = 'msdeploy' - @args = {} + def initialize(*args, &task_block) + setup_ivars(args) - yield self if block_given? - define + define(args, &task_block) end - def log_file - @log_file || "#{@name}.log" + private + def setup_ivars(args) + @name = args.shift || :msdeploy + + @msdeploy = 'msdeploy' + @args = {} + @log_file = "#{@name}.log" end - private - def define - CLEAN.include(log_file) + def define(args, &task_block) + desc 'Deploy application' unless Rake.application.last_description - desc "Deploy #{deploy_source(args)}" - task @name do + task(name, *args) do |_, task_args| + task_block.call(*[self, task_args].slice(0, task_block.arity)) if task_block + mapper = Mapper.new(:MSDeploy) - cmd = [quote(msdeploy), mapper.map(args)] + 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/