Class: Rant::DirTask

Inherits:
Task show all
Defined in:
lib/rant/import/nodes/default.rb

Overview

An instance of this class is a task to create a single directory.

Instance Attribute Summary

Attributes inherited from Task

#receiver

Instance Method Summary collapse

Methods inherited from Task

#<<, #each_dep, #enhance, #fail?, #has_actions?, #invoked?, #prerequisites, #source

Methods included from Node

#inspect

Constructor Details

#initialize(*args) ⇒ DirTask

Returns a new instance of DirTask.



388
389
390
391
392
# File 'lib/rant/import/nodes/default.rb', line 388

def initialize(*args)
    super
    @ts = T0
    @isdir = nil
end

Instance Method Details

#each_target {|name| ... } ⇒ Object

Yields:

  • (name)


454
455
456
457
# File 'lib/rant/import/nodes/default.rb', line 454

def each_target
    goto_task_home
    yield name
end

#file_target?Boolean

Returns:

  • (Boolean)


413
414
415
# File 'lib/rant/import/nodes/default.rb', line 413

def file_target?
    true
end

#handle_node(dep, opt) ⇒ Object



417
418
419
420
421
422
423
424
425
426
427
# File 'lib/rant/import/nodes/default.rb', line 417

def handle_node(dep, opt)
    #STDERR.puts "treating #{dep.full_name} as file dependency"
    return true if dep.file_target? && dep.invoke(opt)
	    if File.exist? dep.name
        File.mtime(dep.name) > @ts
    elsif !dep.file_target?
		@rac.err_msg @rac.pos_text(rantfile.path, line_number),
		    "in prerequisites: no such file: `#{dep.full_name}'"
		self.fail
	    end
end

#handle_non_node(dep, opt) ⇒ Object



434
435
436
437
438
439
440
441
442
# File 'lib/rant/import/nodes/default.rb', line 434

def handle_non_node(dep, opt)
           goto_task_home
    unless File.exist? dep
	@rac.err_msg @rac.pos_text(rantfile.path, line_number),
	    "in prerequisites: no such file or task: `#{dep}'"
	self.fail
    end
    [dep, @block && File.mtime(dep) > @ts]
end

#handle_timestamped(dep, opt) ⇒ Object



429
430
431
432
# File 'lib/rant/import/nodes/default.rb', line 429

def handle_timestamped(dep, opt)
    return @block if dep.invoke opt
    @block && dep.timestamp(opt) > @ts
end

#invoke(opt = INVOKE_OPT) ⇒ Object



394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
# File 'lib/rant/import/nodes/default.rb', line 394

def invoke(opt = INVOKE_OPT)
    return circular_dep if @run
    @run = true
    begin
	return if done?
	goto_task_home
	@isdir = test(?d, @name)
	if @isdir
	    @ts = @block ? test(?M, @name) : Time.now
	    internal_invoke opt, false
	else
	    @ts = T0
	    internal_invoke opt, true
	end
    ensure
	@run = false
    end
end

#runObject



444
445
446
447
448
449
450
451
452
# File 'lib/rant/import/nodes/default.rb', line 444

def run
           return if @rac.running_task(self)
    @rac.sys.mkdir @name unless @isdir
    if @block
	@block.arity == 0 ? @block.call : @block[self]
	goto_task_home
	@rac.sys.touch @name
    end
end