Class: Katte::Recipe::Node
- Inherits:
-
Object
- Object
- Katte::Recipe::Node
show all
- Includes:
- Node::Base
- Defined in:
- lib/katte/recipe/node.rb
Instance Method Summary
collapse
Methods included from Node::Base
#add_child, #add_parent, #children, #name, #parents, #requires, #run?
Constructor Details
#initialize(params) ⇒ Node
Returns a new instance of Node.
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/katte/recipe/node.rb', line 13
def initialize(params)
@name = params[:name]
@path = params[:path]
@requires = params[:require]
@file_type = params[:file_type]
@output = params[:output] || []
@period = params[:period] || 'day'
@options = params[:options] || {}
@parents = []
@children = []
end
|
Instance Method Details
#_descendants(enum) ⇒ Object
63
64
65
66
67
68
69
|
# File 'lib/katte/recipe/node.rb', line 63
def _descendants(enum)
children.each {|node|
enum << node
node._descendants(enum)
}
enum
end
|
#descendants ⇒ Object
60
61
62
|
# File 'lib/katte/recipe/node.rb', line 60
def descendants
Enumerator.new {|enum| _descendants(enum) }
end
|
#open ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/katte/recipe/node.rb', line 26
def open
out_r, out_w = IO.pipe
err_r, err_w = IO.pipe
result = yield out_w, err_w
[out_w, err_w].each {|io| io.close unless io.closed? }
out_a, err_a = out_r.to_a.join, err_r.to_a.join
[out_r, err_r].each {|io| io.close unless io.closed? }
Katte.app.logger.warn("#{self.name} -- result is empty") if out_a.empty?
@output.reduce(out_a) {|stream, o| o.out(self, stream) }
@output.reduce(err_a) {|stream, o| o.err(self, stream) }
result
ensure
[out_r, out_w, err_r, err_w].each {|io| io.close unless io.closed? }
end
|
#run(driver) ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/katte/recipe/node.rb', line 46
def run(driver)
unless @file_type
Katte.app.logger.error("no file type specified for %s" % @name)
return
end
Katte::ThreadPool.instance.push {
Katte.app.logger.info("[start] #{self.name}")
result = file_type.execute(self)
Katte.app.logger.info(sprintf("[%s] #{self.name}", (result ? "success" : "fail")))
result ? driver.done(self) : driver.fail(self)
}
end
|