Class: RakeJava::Copier
Overview
A simple class for copying files from various places to a single target directory. You can tell it to just copy files if they’re newer than the target version.
Instance Attribute Summary collapse
-
#files ⇒ Object
Returns the value of attribute files.
Instance Method Summary collapse
- #copy ⇒ Object
- #force ⇒ Object
-
#initialize(dest_dir, &block) ⇒ Copier
constructor
A new instance of Copier.
Constructor Details
#initialize(dest_dir, &block) ⇒ Copier
Returns a new instance of Copier.
371 372 373 374 375 376 |
# File 'lib/rakejava.rb', line 371 def initialize dest_dir, &block @files = [] @dest_dir = dest_dir.sub(%r[/+$], '') # remove trailing slashes @check_date = true block.call(self) end |
Instance Attribute Details
#files ⇒ Object
Returns the value of attribute files.
369 370 371 |
# File 'lib/rakejava.rb', line 369 def files @files end |
Instance Method Details
#copy ⇒ Object
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 |
# File 'lib/rakejava.rb', line 382 def copy dirs = Set.new @files.each do |copy_files| src_files = copy_files.to_a if copy_files.kind_of?(CopyFiles) partials = src_files.map { |f| f.sub(%r[^#{copy_files.root}/], '') } else partials = src_files end partials.each do |part| if copy_files.kind_of?(CopyFiles) src_path = "#{copy_files.root}/#{part}" dest_dir = @dest_dir + (copy_files.dest_path ? "/#{copy_files.dest_path}" : '') if copy_files.flattened? dest_path = "#{dest_dir}/#{File.basename(src_path)}" else dest_path = "#{dest_dir}/#{part}" end else src_path = part dest_path = "#{@dest_dir}/#{part}" end if File.directory?(src_path) next end if @check_date && File.exist?(dest_path) src_time = File.mtime(src_path) dest_time = File.mtime(dest_path) if src_time <= dest_time next end end # Ensure the path parent = File.dirname(dest_path) unless dirs.include?(parent) dirs << parent mkdir_p parent end # Copy the file cp src_path, dest_path end end end |
#force ⇒ Object
378 379 380 |
# File 'lib/rakejava.rb', line 378 def force @check_date = false end |