Class Uttk::Filters::Compact
In: lib/uttk/filters/Compact.rb
Parent: Id

Methods

new   new_leaf   new_node   up  

Included Modules

Concrete

Classes and Modules

Class Uttk::Filters::Compact::InternalError

Public Class methods

[Source]

# File lib/uttk/filters/Compact.rb, line 17
      def initialize ( *a, &b )
        super
        @record = {}
      end

Public Instance methods

[Source]

# File lib/uttk/filters/Compact.rb, line 59
      def new_leaf ( path, leaf )
        if @record.empty?
          # We are recording nothing so we transmit the message as is.
          super
        else
          # Each buffer receive the message
          @record.each do |path_s, buf|
            buf.first.update(:new_leaf, path, leaf)
          end
        end
      end

Protected Instance methods

[Source]

# File lib/uttk/filters/Compact.rb, line 23
      def new_node ( path, node )
        if type = node.options[:type]
          unless type.is_a? Class
            if type.is_a? String and type =~ /^[A-Z]([a-zA-Z_]|::)*$/
              type = eval type
            else
              raise ArgumentError, "bad type name #{type} : #{type.class}"
            end
          end
          # We record the flow if the type is NOT a subclass of Composite nor
          # a subclass of SubCmd (SubCmd and Composite included)
          unless type <= Strategies::Composite or type <= Strategies::SubCmd
            @record[path.to_s] = [Buffer.new, node]
          end
        end
        if node.segment == :attributes
          @record[path.to_s] = [Buffer.new, node]
        end
      end

[Source]

# File lib/uttk/filters/Compact.rb, line 45
      def up ( path )
        if buf = @record[path.to_s] # If this path was recorded
          @record.delete path.to_s
          path << buf.last
          # We dump it as leaf
          leaf = buf.first.buffer.rpath_find(:first, path.to_regex_path_string)
          raise InternalError, 'in Compact#up the leaf cannot be nil' if leaf.nil?
          notif :new_leaf, path, leaf
        end
        super
      end

[Validate]