Sha256: f0758bc70a733eeaf8e72c8fa2712a08179dab1af5415d92ae2b8c0e1e6a4919

Contents?: true

Size: 1.17 KB

Versions: 3

Compression:

Stored size: 1.17 KB

Contents

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

module Rake::Funnel::Tasks
  class Copy < Rake::TaskLib
    attr_accessor :name, :source, :target

    def initialize(name = :copy)
      @name = name

      @source = []
      @target = nil

      yield self if block_given?
      define
    end

    private
    def define
      target && CLEAN.include(target)

      desc "Copy #{files.join(', ')} to #{target}"
      task name do
        raise 'Target not defined' unless target

        files.each do |source|
          next if File.directory?(source)

          target = target_path(source)

          dir = File.dirname(target)
          RakeFileUtils.mkdir_p(dir) unless File.directory?(dir)

          RakeFileUtils.cp(source, target)
        end
      end

      self
    end

    def files
      Rake::Funnel::Support::Finder.new(source, self, 'No files found.').all_or_default
    end

    def target_path(file)
      target_relative = Pathname.new(file).relative_path_from(Pathname.new(common_path)).to_s
      File.join(target, target_relative)
    end

    def common_path
      @common_path ||= files.common_path
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rake-funnel-0.0.4.pre lib/rake/funnel/tasks/copy.rb
rake-funnel-0.0.2.pre lib/rake/funnel/tasks/copy.rb
rake-funnel-0.0.1.pre lib/rake/funnel/tasks/copy.rb