Class Uttk::Filters::Buffer
In: lib/uttk/filters/Buffer.rb
Parent: Filter

This basic filter observe a logger and bufferize all received messages, with a tree formatting. The buffer can be flushed when the data are not usefull anymore. That imply that another entity, a kind of controller, should always be connected to this class.

The buffer is simple, all notified datas are directly putted inside, and when a flush is needed (or asked) it erases all datas. So, it is possible to think to a new class, derived from this one, which examin more precisely the notifications, and stock into the buffer just the desired. It could do the same for flush the buffer, just clear some part of the buffer. The tool Rpath could be very usefull to do that.

The messages are putted into the buffer in order to make a tree, only with Hash and OHash objects. So, that tree could be given at any time.

The main utiliy of this class is to provide exactly all the datas that another entity want. Moreover, that ones are given under a tree form, which allow simple navigation inside, especialy with the Rpath tool.

Methods

clear   close   empty?   new   new_leaf   new_node   reset   up   update  

Included Modules

Concrete

Classes and Modules

Module Uttk::Filters::Buffer::Assertions

Attributes

buffer  [R] 

Public Class methods

[Source]

# File lib/uttk/filters/Buffer.rb, line 39
      def initialize(*a, &b)
        super
        reset
      end

Public Instance methods

clear()

Alias for reset

[Source]

# File lib/uttk/filters/Buffer.rb, line 97
      def empty?
        @buffer.is_a? Hash and @buffer.empty?
      end

[Source]

# File lib/uttk/filters/Buffer.rb, line 44
      def reset
        @buffer = {}
        @path = [@buffer]
        @last_node = nil
        @reset_planned = false
      end

[Source]

# File lib/uttk/filters/Buffer.rb, line 92
      def update ( *a, &b )
        reset if @reset_planned
        super
      end

Protected Instance methods

[Source]

# File lib/uttk/filters/Buffer.rb, line 85
      def close
        super
        notif :new_leaf, [], @buffer
        @reset_planned = true
      end

[Source]

# File lib/uttk/filters/Buffer.rb, line 63
      def new_leaf ( path, leaf )
        super
        if @last_node.nil?
          @buffer = leaf
          @path = [@buffer]
        else
          father = @path[-2]
          if father[@last_node].is_a? Hash
            father[@last_node] = leaf
          else
            father[@last_node] = [father[@last_node], leaf]
          end
        end
      end

[Source]

# File lib/uttk/filters/Buffer.rb, line 53
      def new_node ( path, node )
        super
        value = (node.options[:ordered]) ? OHash.new : {}
        value[:strategy] = node.options[:type] if node.options.has_key? :type
        @path.last[node.segment] = value
        @path << value
        @last_node = node.segment
      end

[Source]

# File lib/uttk/filters/Buffer.rb, line 79
      def up ( path )
        super
        @path.pop if @path.size > 1
      end

[Validate]