Class: TTK::Filters::Saver

Inherits:
Filter show all
Includes:
Concrete
Defined in:
lib/ttk/filters/Saver.rb

Overview

This very basic filter, observe a logger, and save all received messages, without any formatting.

With this observer you save a sort of execution trace. After that you can apply to another logger the same message sequence.

You can also simply check that two results are equal, for that, just compare the sequence message.

Instance Method Summary collapse

Constructor Details

#initializeSaver

Returns a new instance of Saver.



25
26
27
# File 'lib/ttk/filters/Saver.rb', line 25

def initialize
  @out = []
end

Instance Method Details

#each(&block) ⇒ Object



52
53
54
# File 'lib/ttk/filters/Saver.rb', line 52

def each ( &block )
  @out.each(&block)
end

#getObject



38
39
40
# File 'lib/ttk/filters/Saver.rb', line 38

def get
  @out.dup
end

#repeat(log) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/ttk/filters/Saver.rb', line 42

def repeat ( log )
  if !@out.empty? and @out[0][1] == 'root'
    @out[0][1] = 'sub root'
  end
  @out.each do |a|
    a[2] = a[2].to_sym if a[2].is_a? String
    log.send(*a)
  end
end

#update(*args) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/ttk/filters/Saver.rb', line 29

def update ( *args )
  msg, path, node, type = args
  a = [msg]
  a << path.last.first if msg == :new_node
  a << node unless node.nil?
  a << type unless type.nil?
  @out << a
end