class Runbook::Entity
Attributes
dsl[R]
labels[R]
title[R]
Public Class Methods
inherited(child_class)
click to toggle source
# File lib/runbook/entity.rb, line 6 def self.inherited(child_class) child_class.const_set(:DSL, Runbook::DSL.class) end
new(title, tags: [], labels: {}, parent: nil)
click to toggle source
# 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
Public Instance Methods
_render_metadata(items, item, metadata, index)
click to toggle source
# 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
_run_metadata(items, item, metadata, index)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/runbook/entity.rb, line 20 def add(item) items << item item.parent = self end
dynamic!()
click to toggle source
# File lib/runbook/entity.rb, line 76 def dynamic! items.each(&:dynamic!) @dynamic = true end
items()
click to toggle source
# File lib/runbook/entity.rb, line 25 def items @items ||= [] end
method_missing(method, *args, &block)
click to toggle source
Calls superclass method
# File lib/runbook/entity.rb, line 29 def method_missing(method, *args, &block) if dsl.respond_to?(method) dsl.send(method, *args, &block) else super end end
render(view, output, metadata)
click to toggle source
# 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)
click to toggle source
Calls superclass method
# File lib/runbook/entity.rb, line 37 def respond_to?(name, include_private = false) !!(dsl.respond_to?(name) || super) end
run(run, metadata)
click to toggle source
# 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) # Optimization 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