Class: Runbook::Entity
Instance Attribute Summary collapse
Attributes inherited from Node
#parent
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
-
#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?, #parent_entity, #visited!, #visited?
Constructor Details
#initialize(title, tags: [], labels: {}, parent: nil) ⇒ Entity
Returns a new instance of Entity.
12
13
14
15
16
17
18
|
# File 'lib/runbook/entity.rb', line 12
def initialize(title, tags: [], labels: {}, parent: nil)
@title = title
@tags = tags
@labels = labels
@parent = parent
@dsl = "#{self.class}::DSL".constantize.new(self)
end
|
Instance Attribute Details
#dsl ⇒ Object
Returns the value of attribute dsl.
10
11
12
|
# File 'lib/runbook/entity.rb', line 10
def dsl
@dsl
end
|
#labels ⇒ Object
Returns the value of attribute labels.
10
11
12
|
# File 'lib/runbook/entity.rb', line 10
def labels
@labels
end
|
Returns the value of attribute tags.
10
11
12
|
# File 'lib/runbook/entity.rb', line 10
def tags
@tags
end
|
#title ⇒ Object
Returns the value of attribute title.
10
11
12
|
# File 'lib/runbook/entity.rb', line 10
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
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/runbook/entity.rb', line 81
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
|
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
# File 'lib/runbook/entity.rb', line 94
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
124
125
126
127
|
# File 'lib/runbook/entity.rb', line 124
def _should_retraverse?(run, metadata)
return false unless metadata[:reverse]
run.start_at_is_substep?(self, metadata)
end
|
#_should_reverse?(run, metadata) ⇒ Boolean
119
120
121
122
|
# File 'lib/runbook/entity.rb', line 119
def _should_reverse?(run, metadata)
return false unless metadata[:reverse]
run.past_position?(metadata[:position], metadata[:start_at])
end
|
#add(item) ⇒ Object
20
21
22
23
|
# File 'lib/runbook/entity.rb', line 20
def add(item)
items << item
item.parent = self
end
|
#dynamic! ⇒ Object
76
77
78
79
|
# File 'lib/runbook/entity.rb', line 76
def dynamic!
items.each(&:dynamic!)
@dynamic = true
end
|
#items ⇒ Object
25
26
27
|
# File 'lib/runbook/entity.rb', line 25
def items
@items ||= []
end
|
#render(view, output, metadata) ⇒ Object
41
42
43
44
45
46
47
48
49
|
# File 'lib/runbook/entity.rb', line 41
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
37
38
39
|
# File 'lib/runbook/entity.rb', line 37
def respond_to?(name, include_private = false)
!!(dsl.respond_to?(name) || super)
end
|
#run(run, metadata) ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/runbook/entity.rb', line 51
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
|