| 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.
| buffer | [R] |
# File lib/uttk/filters/Buffer.rb, line 44 def reset @buffer = {} @path = [@buffer] @last_node = nil @reset_planned = false end
# File lib/uttk/filters/Buffer.rb, line 85 def close super notif :new_leaf, [], @buffer @reset_planned = true end
# 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
# 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