Sha256: bc573f4ea850c2c25549b20dba2b87608b81fc49981ad91e5c78fa0902b875ce

Contents?: true

Size: 1004 Bytes

Versions: 3

Compression:

Stored size: 1004 Bytes

Contents

module Buildr

  # A file task that concatenates all its prerequisites to create a new file.
  #
  # For example:
  #   concat("master.sql"=>["users.sql", "orders.sql", reports.sql"]
  #
  # See also Buildr#concat.
  class ConcatTask < Rake::FileTask
    def initialize(*args) #:nodoc:
      super
      enhance do |task|
        content = prerequisites.inject("") do |content, prereq|
          content << File.read(prereq.to_s) if File.exists?(prereq) && !File.directory?(prereq)
          content
        end
        File.open(task.name, "w") { |file| file.write content }
      end
    end
  end

  # :call-seq:
  #    concat(target=>files) => task
  #
  # Creates and returns a file task that concatenates all its prerequisites to create
  # a new file. See #ConcatTask.
  #
  # For example:
  #   concat("master.sql"=>["users.sql", "orders.sql", reports.sql"]
  def concat(args)
    file, deps = Rake.application.resolve_args(args)
    ConcatTask.define_task File.expand_path(file)=>deps
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
buildr-0.19.0 lib/tasks/concat.rb
buildr-0.20.0 lib/tasks/concat.rb
buildr-0.21.0 lib/tasks/concat.rb