Class: Runbook::Entity
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
-
#_render_metadata(items, item, metadata, index) ⇒ Object
-
#_run_metadata(items, item, metadata, index) ⇒ Object
-
#_should_retraverse?(run, metadata) ⇒ Boolean
-
#_should_reverse?(run, metadata) ⇒ Boolean
-
#add(item) ⇒ Object
-
#dynamic! ⇒ Object
-
#initialize(title, tags: [], labels: {}, parent: nil) ⇒ Entity
constructor
A new instance of Entity.
-
#items ⇒ Object
-
#method_missing(method, *args, &block) ⇒ Object
-
#render(view, output, metadata) ⇒ Object
-
#respond_to?(name, include_private = false) ⇒ Boolean
-
#run(run, metadata) ⇒ Object
#_execute_after_hooks, #_execute_around_hooks, #_execute_before_hooks, #invoke_with_hooks
Methods inherited from Node
#dynamic?, #visited!, #visited?
Constructor Details
#initialize(title, tags: [], labels: {}, parent: nil) ⇒ Entity
Returns a new instance of Entity.
13
14
15
16
17
18
19
|
# File 'lib/runbook/entity.rb', line 13
def initialize(title, tags: [], labels: {}, parent: nil)
@title = title
@tags = tags
@labels = labels
@parent = parent
@dsl = "#{self.class}::DSL".constantize.new(self)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
30
31
32
33
34
35
36
|
# File 'lib/runbook/entity.rb', line 30
def method_missing(method, *args, &block)
if dsl.respond_to?(method)
dsl.send(method, *args, &block)
else
super
end
end
|
Instance Attribute Details
#dsl ⇒ Object
Returns the value of attribute dsl.
11
12
13
|
# File 'lib/runbook/entity.rb', line 11
def dsl
@dsl
end
|
#labels ⇒ Object
Returns the value of attribute labels.
11
12
13
|
# File 'lib/runbook/entity.rb', line 11
def labels
@labels
end
|
#parent ⇒ Object
Returns the value of attribute parent.
10
11
12
|
# File 'lib/runbook/entity.rb', line 10
def parent
@parent
end
|
Returns the value of attribute tags.
11
12
13
|
# File 'lib/runbook/entity.rb', line 11
def tags
@tags
end
|
#title ⇒ Object
Returns the value of attribute title.
11
12
13
|
# File 'lib/runbook/entity.rb', line 11
def title
@title
end
|
Class Method Details
.inherited(child_class) ⇒ Object
6
7
8
|
# File 'lib/runbook/entity.rb', line 6
def self.inherited(child_class)
child_class.const_set(:DSL, Runbook::DSL.class)
end
|
Instance Method Details
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/runbook/entity.rb', line 82
def _render_metadata(items, item, metadata, index)
index = items.select do |item|
item.is_a?(Entity)
end.index(item)
metadata.merge(
{
depth: metadata[:depth] + 1,
index: index,
}
)
end
|
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
# File 'lib/runbook/entity.rb', line 95
def _run_metadata(items, item, metadata, index)
pos_index = items.select do |item|
item.is_a?(Entity) &&
!item.is_a?(Runbook::Entities::Setup)
end.index(item)
if pos_index
if metadata[:position].empty?
pos = "#{pos_index + 1}"
else
pos = "#{metadata[:position]}.#{pos_index + 1}"
end
else
pos = metadata[:position]
end
metadata.merge(
{
depth: metadata[:depth] + 1,
index: index,
position: pos,
}
)
end
|
#_should_retraverse?(run, metadata) ⇒ Boolean
125
126
127
128
|
# File 'lib/runbook/entity.rb', line 125
def _should_retraverse?(run, metadata)
return false unless metadata[:reverse]
run.start_at_is_substep?(self, metadata)
end
|
#_should_reverse?(run, metadata) ⇒ Boolean
120
121
122
123
|
# File 'lib/runbook/entity.rb', line 120
def _should_reverse?(run, metadata)
return false unless metadata[:reverse]
run.past_position?(metadata[:position], metadata[:start_at])
end
|
#add(item) ⇒ Object
21
22
23
24
|
# File 'lib/runbook/entity.rb', line 21
def add(item)
items << item
item.parent = self
end
|
#dynamic! ⇒ Object
77
78
79
80
|
# File 'lib/runbook/entity.rb', line 77
def dynamic!
items.each(&:dynamic!)
@dynamic = true
end
|
#items ⇒ Object
26
27
28
|
# File 'lib/runbook/entity.rb', line 26
def items
@items ||= []
end
|
#render(view, output, metadata) ⇒ Object
42
43
44
45
46
47
48
49
50
|
# File 'lib/runbook/entity.rb', line 42
def render(view, output, metadata)
invoke_with_hooks(view, self, output, metadata) do
view.render(self, output, metadata)
items.each_with_index do |item, index|
new_metadata = _render_metadata(items, item, metadata, index)
item.render(view, output, new_metadata)
end
end
end
|
#respond_to?(name, include_private = false) ⇒ Boolean
38
39
40
|
# File 'lib/runbook/entity.rb', line 38
def respond_to?(name, include_private = false)
!!(dsl.respond_to?(name) || super)
end
|
#run(run, metadata) ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/runbook/entity.rb', line 52
def run(run, metadata)
return if _should_reverse?(run, metadata)
return if dynamic? && visited?
invoke_with_hooks(run, self, metadata) do
run.execute(self, metadata)
next if _should_reverse?(run, metadata)
loop do
items.each_with_index do |item, index|
new_metadata = _run_metadata(items, item, metadata, index)
break if _should_reverse?(run, new_metadata)
item.run(run, new_metadata)
end
if _should_retraverse?(run, metadata)
metadata[:reverse] = false
else
break
end
end
end
self.visited!
end
|