Module: Nake
- Included in:
- DSL
- Defined in:
- lib/nake/struct_hash.rb,
lib/nake.rb,
lib/nake/dsl.rb,
lib/nake/argv.rb,
lib/nake/rake.rb,
lib/nake/rule.rb,
lib/nake/task.rb,
lib/nake/runner.rb,
lib/nake/helpers.rb,
lib/nake/template.rb,
lib/nake/file_task.rb,
lib/nake/abstract_task.rb
Overview
options.extend(HashStructMixin) options.name options.force?
Defined Under Namespace
Modules: ArgvParser, DSL, HashStructMixin, PackageMixin, PrintHelpers, RakeDSL, TaskHelpers
Classes: AbstractTask, ErbTemplate, FileTask, Rule, Task, Template
Class Method Summary
collapse
Class Method Details
I was drunk so you might found this code not very clear. But it’s clear for me and it works.
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/nake.rb', line 36
def self.args
@@args ||= begin
Hash.new.tap do |hash|
hash.define_singleton_method(:[]) do |name|
names, value = self.find { |names, block| names.include?(name) }
return value
end
hash.define_singleton_method(:[]=) do |*names, proc|
super(names, proc)
end
end
end
end
|
25
26
27
28
29
|
# File 'lib/nake.rb', line 25
def self.coloring
@@coloring
rescue NameError
@@coloring = STDIN.tty?
end
|
.coloring=(boolean) ⇒ Object
31
32
33
|
# File 'lib/nake.rb', line 31
def self.coloring=(boolean)
@@coloring = boolean
end
|
15
16
17
18
19
|
# File 'lib/nake.rb', line 15
def self.debug
@@debug
rescue NameError
@@debug = true
end
|
.debug=(boolean) ⇒ Object
21
22
23
|
# File 'lib/nake.rb', line 21
def self.debug=(boolean)
@@debug = boolean
end
|
.parse(args = ARGV) ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/nake.rb', line 51
def self.parse(args = ARGV)
default = {nake: Array.new, task: Array.new}
args.inject(default) do |hash, argument|
if argument.match(/^-/) && hash[:task].empty?
hash[:nake].push(argument)
elsif File.exist?(argument) && hash[:file].nil? hash[:file] = argument
else
hash[:task].push(argument)
end
hash
end
end
|
6
7
8
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/nake/runner.rb', line 6
def self.run
begin
Nake.parse
rescue Exception => exception
puts "~ Arguments parsed into #{Nake.parse.inspect.green}"
puts "Exception occured during parsing arguments"
print_exception_with_backtrace_and_abort(exception)
else
if Nake.parse[:nake] && Nake.parse[:nake].include?("--debug") puts "~ Arguments parsed into #{Nake.parse.inspect.green}"
end
end
if Nake.parse[:file]
begin
load Nake.parse[:file]
rescue Exception => exception
print_exception_with_backtrace_and_abort(exception)
end
elsif File.exist?("tasks.rb")
Nake.parse[:file] = "tasks.rb"
else
abort "You have to specify a file with tasks"
end
begin
original_args = Nake.parse.dup
Nake.run_args
rescue SystemExit => exception
exit exception.status
rescue Exception => exception
puts "~ Arguments parsed into #{Nake.parse.inspect.green}"
puts "Exception occured setting nake flags"
print_exception_with_backtrace_and_abort(exception)
else
if Nake.debug && Nake.parse != original_args
puts "~ Arguments changed into #{Nake.parse.inspect.green}"
end
end
begin
Nake.run_task
rescue TaskNotFound => exception
abort exception.message
rescue SystemExit => exception
exit exception.status
rescue Exception => exception
print_exception_with_backtrace_and_abort(exception)
end
exit $? ? $?.exitstatus.to_i : 0
end
|
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/nake.rb', line 65
def self.run_args
Nake.parse[:nake].each do |argument|
unless self.args[argument]
abort "Unrecognized argument: #{argument}"
end
name, value = ArgvParser.parse(argument)
if name
info "Invoking argument #{argument} with #{name} = #{value}"
self.args[argument].call(name, value)
else
info "Invoking argument #{argument} without any arguments"
self.args[argument].call
end
end
end
|
89
90
91
92
93
94
95
96
97
98
99
100
|
# File 'lib/nake.rb', line 89
def self.run_task
Task.boot
name, *args = Nake.parse[:task]
task = Task[name]
if name.nil?
raise TaskNotFound, "You have to specify a task you want to run!"
elsif task.nil?
raise TaskNotFound, "Task with name #{name} doesn't exist"
else
task.run(args)
end
end
|
5
6
7
8
9
|
# File 'lib/nake.rb', line 5
def self.verbose
@@verbose
rescue NameError
@@verbose = true
end
|
.verbose=(boolean) ⇒ Object
11
12
13
|
# File 'lib/nake.rb', line 11
def self.verbose=(boolean)
@@verbose = boolean
end
|