Method: Tap::Support::Audit#trail
- Defined in:
- lib/tap/support/audit.rb
#trail(trail = [], &block) ⇒ Object
Recursively collects an audit trail leading to self. Single sources are collected into the trail directly, while multiple sources are collected into arrays.
_a = Audit.new(:one, 1)
_b = Audit.new(:two, 2, _a)
_b.trail # => [_a,_b]
_a = Audit.new(:one, 1)
_b = Audit.new(:two, 2)
_c = Audit.new(:three, 3, [_a, _b])
_c.trail # => [[[_a],[_b]],_c]
A block may be provided to collect a specific audit attribute instead of the audit itself.
_c.trail {|audit| audit.value } # => [[[1],[2]],3]
292 293 294 295 296 297 298 299 300 301 302 303 |
# File 'lib/tap/support/audit.rb', line 292 def trail(trail=[], &block) trail.unshift(block_given? ? block.call(self) : self) case @source when Audit @source.trail(trail, &block) when Array trail.unshift @source.collect {|audit| audit.trail(&block) } end trail end |