Class: Rant::Generators::Clean

Inherits:
Object
  • Object
show all
Defined in:
lib/rant/import/clean.rb

Class Method Summary collapse

Class Method Details

.rant_gen(rac, ch, args, &block) ⇒ Object


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rant/import/clean.rb', line 9

def self.rant_gen(rac, ch, args, &block)
	# validate args
	if args.size > 1
 rac.abort_at(ch, "Clean doesn't take more than one argument.")
	end
	tname = args.first || "clean"

	# set var with task name to a MultiFileList
	case rac.var[tname]
	when nil
 rac.var[tname] = Rant::MultiFileList.new(rac)
	when Rant::RacFileList
 ml = Rant::MultiFileList.new(rac)
 rac.var[tname] = ml.add(rac.var[tname])
	when Rant::MultiFileList
 # ok, nothing to do
	else
 # TODO: refine error message
 rac.abort_at(ch,
		"var `#{tname}' already exists.",
		"Clean uses var with the same name as the task name.")
	end

	# create task
	rac.task :__caller__ => ch, tname => [] do |t|
 rac.var[tname].each_entry { |entry|
		if test ?e, entry
  if test ?f, entry
			rac.cx.sys.rm_f entry
  else
			rac.cx.sys.rm_rf entry
  end
		end
 }
	end
end