Class: Uttk::Logger::Backend

Inherits:
Object
  • Object
show all
Includes:
Abstract
Defined in:
lib/uttk/logger/backend.rb

Overview

A Logger::Backend is a logger observer. It’s react to some methods, which can be compared to shell commands:

At any time `path' is "equivalent to" the shell command `pwd'.
The path argument is a Logger::Path instance.

- new_node ( path, node ):
  - The method new_node is called with the path and a node as arguments.
  - node is a Logger::Segment it contains 2 fields (segment and options)
  - new_node is equivalent to `mkdir node && cd node' in shell.

- new_leaf ( path, leaf ):
  - equivalent to `touch leaf'

- up ( path ):
  - equivalent to `cd ..` (path is given but it's allways the parent path)
  - Change the current path to the parent.

- close ():
  - Close this backend.

Thinking about the notification model

  • either we send complete paths:

      root
      root/sub1
      root/sub1/status
      root/sub1/status/PASS
      root/sub2
      root/sub2/contents[ordered]
      root/sub2/contents[ordered]/t1
      root/sub2/contents[ordered]/t1/status
      root/sub2/contents[ordered]/t1/status/PASS
      root/sub2/contents[ordered]/t2
      root/sub2/contents[ordered]/t2/status
      root/sub2/contents[ordered]/t2/status/FAIL
      root/sub2/status/FAIL(50%)
      root/status/FAIL(75%)
    avantages
      - no more needs to send new_leaf, new_node, and up
      - it's more robust against transformations (up quantity...)
    
  • but we can compress this flow, we send only path of leaves:

    root/sub1/status/PASS
    root/sub2/contents[ordered]/t1/status/PASS
    root/sub2/contents[ordered]/t2/status/FAIL
    root/sub2/status/FAIL(50%)
    root/status/FAIL(75%)
    
  • or even better to avoid the leaf encoding (by ourself), we send the path of the leaf and the leaf:

    ---
      - !lpath root/sub1/status
      - PASS
    ---
      - !lpath root/sub2/contents[ordered]/t1/status
      - PASS
    ---
      - !lpath root/sub2/contents[ordered]/t2/status
      - FAIL
    ---
      - !lpath root/sub2/status
      - FAIL(50%)
    ---
      - !lpath root/status
      - FAIL(75%)
    

The last one is kept in this implementation.

Direct Known Subclasses

Dumpers::Dumper, Filters::Filter

Instance Method Summary collapse

Constructor Details

#initializeBackend

Returns a new instance of Backend.



86
87
88
89
# File 'lib/uttk/logger/backend.rb', line 86

def initialize
  @backend_path = Logger::Path.new
  @open = true
end

Instance Method Details

#update(msg, path = nil, *args) ⇒ Object

Raises:



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/uttk/logger/backend.rb', line 131

def update ( msg, path=nil, *args )
  if msg == :close
    if @open
      @open = false
      return close
    else
      return
    end
  end
  raise UnsupportedMessage, msg if msg != :new_leaf
  path = path.to_logger_path unless path.is_a? Logger::Path
  identical = true
  last_ordered_seg = nil
  path.each_with_index do |x, i|
    y = @backend_path[i]
    last_ordered_seg = i if x.options[:ordered]
    next if x == y
    identical = false
    complete_up i unless y.nil?
    spawn_new_node x
  end
  if msg == :new_leaf and identical and not path.empty? \
      and not last_ordered_seg.nil? # FIXME
    # try to make this assertion more precise to not break some valid tests (sub.yml)
    # raise DuplicatedPath.new(@backend_path, path) if last_ordered_seg.nil?
    last_ordered_seg += 1
    complete_up last_ordered_seg
    path.each_with_index do |x, i|
      next if i < last_ordered_seg
      spawn_new_node x
    end
  end
  new_leaf(path.dup, *args)
end