Class Uttk::Logger::Backend
In: lib/uttk/logger/backend.rb
Parent: Object

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.

Methods

close   new   new_leaf   new_node   up   update  

Included Modules

Abstract

Public Class methods

[Source]

# File lib/uttk/logger/backend.rb, line 86
      def initialize
        @backend_path = Logger::Path.new
        @open = true
      end

Public Instance methods

[Source]

# 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

Protected Instance methods

[Source]

# File lib/uttk/logger/backend.rb, line 107
      def close
      end

[Source]

# File lib/uttk/logger/backend.rb, line 97
      def new_leaf ( path, leaf )
      end

[Source]

# File lib/uttk/logger/backend.rb, line 92
      def new_node ( path, node )
      end

[Source]

# File lib/uttk/logger/backend.rb, line 102
      def up ( path )
      end

[Validate]