Class: Rant::UserTask

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

Overview

A UserTask is equivalent to a Task, but it additionally takes a block (see #needed) which is used to determine if it is needed?.

Instance Attribute Summary

Attributes inherited from Task

#receiver

Instance Method Summary collapse

Methods inherited from Task

#<<, #each_dep, #enhance, #fail?, #handle_node, #handle_non_node, #handle_timestamped, #has_actions?, #invoked?, #prerequisites, #source

Methods included from Node

#inspect

Constructor Details

#initialize(*args) {|_self| ... } ⇒ UserTask

Returns a new instance of UserTask.

Yields:

  • (_self)

Yield Parameters:


239
240
241
242
243
244
245
246
247
248
# File 'lib/rant/import/nodes/default.rb', line 239

def initialize(*args)
    super
    # super will set @block to a given block, but the block is
    # used for initialization, not ment as action
    @block = nil
    @needed = nil
           @target_files = nil
    # allow setting of @block and @needed
    yield self if block_given?
end

Instance Method Details

#act(&block) ⇒ Object


250
251
252
# File 'lib/rant/import/nodes/default.rb', line 250

def act(&block)
    @block = block
end

#each_target(&block) ⇒ Object


262
263
264
265
# File 'lib/rant/import/nodes/default.rb', line 262

def each_target(&block)
    goto_task_home
    @target_files.each(&block) if @target_files
end

#file_target(*args) ⇒ Object


267
268
269
270
271
272
273
274
275
# File 'lib/rant/import/nodes/default.rb', line 267

def file_target(*args)
    args.flatten!
    args << @name if args.empty?
    if @target_files
        @target_files.concat(args)
    else
        @target_files = args
    end
end

#file_target?Boolean

Returns:

  • (Boolean)

258
259
260
# File 'lib/rant/import/nodes/default.rb', line 258

def file_target?
    @target_files and @target_files.include? @name
end

#invoke(opt = INVOKE_OPT) ⇒ Object

We simply override this method and call internal_invoke with the ud_init flag according to the result of a call to the needed block.


280
281
282
283
284
285
286
287
288
289
# File 'lib/rant/import/nodes/default.rb', line 280

def invoke(opt = INVOKE_OPT)
    return circular_dep if @run
    @run = true
    begin
	return if done?
	internal_invoke(opt, ud_init_by_needed)
    ensure
	@run = false
    end
end

#needed(&block) ⇒ Object


254
255
256
# File 'lib/rant/import/nodes/default.rb', line 254

def needed(&block)
    @needed = block
end