Class: Rant::Task

Inherits:
Object show all
Includes:
Node
Defined in:
lib/rant/import/nodes/default.rb

Direct Known Subclasses

DirTask, FileTask, UserTask

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Node

#inspect

Constructor Details

#initialize(rac, name, prerequisites = [], &block) ⇒ Task

Returns a new instance of Task.



38
39
40
41
42
43
44
45
46
47
# File 'lib/rant/import/nodes/default.rb', line 38

def initialize(rac, name, prerequisites = [], &block)
    super()
    @rac = rac or raise ArgumentError, "rac not given"
           @name = name or raise ArgumentError, "name not given"
    @pre = prerequisites || []
    @pre_resolved = false
    @block = block
    @run = false
           @receiver = nil
end

Instance Attribute Details

#receiverObject

Returns the value of attribute receiver.



36
37
38
# File 'lib/rant/import/nodes/default.rb', line 36

def receiver
  @receiver
end

Instance Method Details

#<<(pre) ⇒ Object

Add a prerequisite.



69
70
71
72
# File 'lib/rant/import/nodes/default.rb', line 69

def <<(pre)
    @pre_resolved = false
    @pre << pre
end

#each_depObject

For each non-worker prerequiste, the value returned from yield will replace the original prerequisite (of course only if



190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# File 'lib/rant/import/nodes/default.rb', line 190

def each_dep
    t = nil
    if @pre_resolved
	return @pre.each { |t| yield(t) }
    end
    my_full_name = full_name
    my_project_subdir = project_subdir
    @pre.map! { |t|
	if Node === t
	    # Remove references to self from prerequisites!
	    if t.full_name == my_full_name
		nil
	    else
		yield(t)
		t
	    end
	else
	    t = t.to_s if Symbol === t
	    if t == my_full_name #TODO
		nil
	    else
		#STDERR.puts "selecting `#{t}'"
		selection = @rac.resolve t,
				my_project_subdir
		#STDERR.puts selection.size
		if selection.empty?
		    # use return value of yield
		    yield(t)
		else
		    selection.each { |st| yield(st) }
		    selection
		end
	    end
	end
    }
           if @pre.kind_of? Rant::FileList
               @pre.resolve
           else
               @pre.flatten!
               @pre.compact!
           end
    @pre_resolved = true
end

#enhance(deps = nil, &blk) ⇒ Object

Enhance this task with the given dependencies and blk.



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/rant/import/nodes/default.rb', line 86

def enhance(deps = nil, &blk)
    if deps
	@pre_resolved = false
	@pre.concat deps
    end
    if @block
	if blk
	    first_block = @block
	    @block = lambda { |t|
		first_block[t]
		blk[t]
	    }
	end
    else
	@block = blk
    end
end

#fail?Boolean

True if last task run fail.

Returns:

  • (Boolean)


81
82
83
# File 'lib/rant/import/nodes/default.rb', line 81

def fail?
    @success == false
end

#handle_node(dep, opt) ⇒ Object

Called from internal_invoke. dep is a prerequisite which is_a? Node, but not a FileTask. opt are opts as given to Node#invoke.

Override this method in subclasses to modify behaviour of prerequisite handling.

See also: handle_timestamped, handle_non_node



157
158
159
# File 'lib/rant/import/nodes/default.rb', line 157

def handle_node(dep, opt)
    dep.invoke opt
end

#handle_non_node(dep, opt) ⇒ Object

Override in subclass if specific task can handle non-task-prerequisites.

Notes for overriding: This method should do one of the two following:

1

Fail with an exception.

2

Return two values: replacement_for_dep, update_required

See also: handle_node, handle_timestamped



181
182
183
184
185
# File 'lib/rant/import/nodes/default.rb', line 181

def handle_non_node(dep, opt)
    @rac.err_msg "Unknown task `#{dep}',",
	"referenced in `#{rantfile.path}', line #{@line_number}!"
    self.fail
end

#handle_timestamped(dep, opt) ⇒ Object

Called from internal_invoke. dep is a prerequisite which is_a? FileTask. opt are opts as given to Node#invoke.

Override this method in subclasses to modify behaviour of prerequisite handling.

See also: handle_node, handle_non_node



168
169
170
# File 'lib/rant/import/nodes/default.rb', line 168

def handle_timestamped(dep, opt)
    dep.invoke opt
end

#has_actions?Boolean

True if this task has at least one action (block to be executed) associated.

Returns:

  • (Boolean)


64
65
66
# File 'lib/rant/import/nodes/default.rb', line 64

def has_actions?
           @block or @receiver && @receiver.has_pre_action?
end

#invoke(opt = INVOKE_OPT) ⇒ Object

Returns a true value if task was acutally run. Raises Rant::TaskFail to signal task (or prerequiste) failure.



106
107
108
109
110
111
112
113
114
115
# File 'lib/rant/import/nodes/default.rb', line 106

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

#invoked?Boolean

Was this task ever invoked? If this is true, it doesn’t necessarily mean that the run was successfull!

Returns:

  • (Boolean)


76
77
78
# File 'lib/rant/import/nodes/default.rb', line 76

def invoked?
    !@success.nil?
end

#prerequisitesObject Also known as: deps

Get a list of the names of all prerequisites. The underlying list of prerequisites can’t be modified by the value returned by this method.



52
53
54
# File 'lib/rant/import/nodes/default.rb', line 52

def prerequisites
    @pre.collect { |pre| pre.to_s }
end

#sourceObject

First prerequisite.



58
59
60
# File 'lib/rant/import/nodes/default.rb', line 58

def source
    @pre.first.to_s
end