Module: DSLTasks::TaskMixin
Instance Attribute Summary collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
88
89
90
|
# File 'lib/dsltasks/dsltasks.rb', line 88
def method_missing(name, *args, &block)
run_task(name, *args, block)
end
|
Instance Attribute Details
#__block__ ⇒ Object
Returns the value of attribute __block__.
4
5
6
|
# File 'lib/dsltasks/dsltasks.rb', line 4
def __block__
@__block__
end
|
#__lib_dirs__ ⇒ Object
Returns the value of attribute lib_dirs.
8
9
10
|
# File 'lib/dsltasks/dsltasks.rb', line 8
def __lib_dirs__
@__lib_dirs__
end
|
#__lib_stack__ ⇒ Object
Returns the value of attribute lib_stack.
7
8
9
|
# File 'lib/dsltasks/dsltasks.rb', line 7
def __lib_stack__
@__lib_stack__
end
|
#__name__ ⇒ Object
Returns the value of attribute __name__.
5
6
7
|
# File 'lib/dsltasks/dsltasks.rb', line 5
def __name__
@__name__
end
|
#__parent_task__ ⇒ Object
Returns the value of attribute parent_task.
6
7
8
|
# File 'lib/dsltasks/dsltasks.rb', line 6
def __parent_task__
@__parent_task__
end
|
#__root__ ⇒ Object
Returns the value of attribute __root__.
9
10
11
|
# File 'lib/dsltasks/dsltasks.rb', line 9
def __root__
@__root__
end
|
Instance Method Details
#__caller__ ⇒ Object
30
31
32
|
# File 'lib/dsltasks/dsltasks.rb', line 30
def __caller__()
(DSLTasks::task_stack(@__root__))[-2]
end
|
#__exec__(calling_task, args, block) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/dsltasks/dsltasks.rb', line 19
def __exec__(calling_task, args, block)
rvalue = nil
task_stack = DSLTasks::task_stack(@__root__)
task_stack.push self
unless block.nil?
args << block
end
rvalue = instance_exec(*args, &@__block__)
task_stack.pop
return rvalue
end
|
#__initialize_task_mixin__(opts = {}) ⇒ Object
10
11
12
13
14
15
16
17
18
|
# File 'lib/dsltasks/dsltasks.rb', line 10
def __initialize_task_mixin__(opts={})
@__parent_task__ = opts[:parent]
@__name__ = opts[:name]
@__block__ = opts[:block]
@__lib_stack__ = opts[:lib_stack]
@__lib_dirs__ = opts[:lib_dirs] || (opts[:parent] ? opts[:parent].__lib_dirs__ : [])
@__root__ = opts[:root] || self
@__tasks__ = Hash.new
end
|
#lib(lib_name) ⇒ Object
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
66
67
68
|
# File 'lib/dsltasks/dsltasks.rb', line 33
def lib(lib_name)
lib_name = lib_name.to_s
if lib_name.start_with?('/')
if File.exist?(lib_name)
unless @__lib_stack__.include?(lib_name)
@__lib_stack__.push(File.expand_path(lib_name))
instance_eval(File.read(lib_name), File.expand_path(lib_name))
@__lib_stack__.pop
end
else
raise "Lib file not found: #{lib_name}"
end
else
dirnames = [File.dirname(@__lib_stack__[-1]), *@__lib_dirs__]
fnames = dirnames.map {|d| File.join(d, lib_name)}
fnames.map! {|f| f.end_with?('.rb') ? f : f+'.rb'}
found_lib = false
fnames.each do |fname|
if File.exist?(fname)
unless @__lib_stack__.include?(fname)
@__lib_stack__.push(File.expand_path(fname))
instance_eval(File.read(fname), File.expand_path(fname))
@__lib_stack__.pop
end
found_lib = true
break
end
end
if !found_lib
raise "Lib file not found in possible locations: #{fnames.join(',')}"
end
end
end
|
#respond_to_missing?(name, *args) ⇒ Boolean
91
92
93
94
95
96
97
98
99
|
# File 'lib/dsltasks/dsltasks.rb', line 91
def respond_to_missing?(name, *args)
if @__tasks__.has_key?(name.to_sym)
return true
elsif @__parent_task__
return @__parent_task__.respond_to_missing?(name, *args)
else
return false
end
end
|
#run_task(name, *args, block) ⇒ Object
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/dsltasks/dsltasks.rb', line 69
def run_task(name, *args, block)
if @__tasks__.has_key?(name.to_sym)
task = @__tasks__[name.to_sym]
return task.__exec__(self, args, block)
elsif @__parent_task__
return @__parent_task__.run_task(name, *args, block)
else
raise "Unrecognized task: #{name}"
end
end
|
#task(name, &block) ⇒ Object
79
80
81
82
83
84
85
86
87
|
# File 'lib/dsltasks/dsltasks.rb', line 79
def task(name, &block)
if block.nil?
if @__tasks__.has_key?(name.to_sym)
return @__tasks__[name.to_sym]
end
else
@__tasks__[name.to_sym] = Task.new(parent: self, lib_stack: @__lib_stack__.clone, name: name.to_sym, block: block, root: @__root__)
end
end
|