Class Uttk::Dumpers::Yaml
In: lib/uttk/dumpers/Yaml.rb
Parent: Dumper

Methods

new   new_leaf   new_node   puts_header   up   update  

Included Modules

Concrete

Constants

MAP_INDENT = 2
MAP_SHIFT = ' ' * MAP_INDENT
OMAP_SHIFT = ' ' * 4

Public Class methods

[Source]

# File lib/uttk/dumpers/Yaml.rb, line 45
      def initialize ( *a, &b )
        super
        @indent = ''
        @stack_indent = []
        @endl = true
        @start = false
        @opts = {:uttk => true, :Inline => true}
      end

Public Instance methods

[Source]

# File lib/uttk/dumpers/Yaml.rb, line 130
      def puts_header
        unless @start
          puts '---'
          @start = true
        end
      end

[Source]

# File lib/uttk/dumpers/Yaml.rb, line 138
      def update ( *a, &b )
        super
        flush
      end

Protected Instance methods

[Source]

# File lib/uttk/dumpers/Yaml.rb, line 89
      def new_leaf ( path, leaf )
        super
        puts_header
        val = leaf
        return if val.respond_to?(:hidden)
        if val.is_a?(String) and val =~ /[\n"]/
          if val =~ /\A[ \t]/
            val = "|#{MAP_INDENT}\n#{val}"
          else
            val = "|\n#{val}"
          end
          val.chomp!
        else
          val = clean_to_yaml(val)
          val = "\n" + val if val =~ /\n/ and val !~ /^\n/
        end
        val.gsub!(/[ \t]*\n/, "\n#@indent")
        print ' ', val, "\n"
        @endl = true
      end

[Source]

# File lib/uttk/dumpers/Yaml.rb, line 55
      def new_node ( path, node )
        super
        puts_header
        options = nil
        if ! path.nil? and ! path.empty?
          options = path.last.options
        end
        puts unless @endl
        @stack_indent << @indent
        self << @indent
        if options.nil? or not options[:ordered]
          @indent += MAP_SHIFT
        else
          self << '- '
          @indent += OMAP_SHIFT
        end
        self << clean_to_yaml(node.segment) << ':'
        if type = node.options[:type]
          if type.is_a? Class
            # FIXME handle this better
            if HAVE_YAML_TAGURI
              self << ' !' << type.taguri.sub(/^tag:.*?:/, '')
            else
              self << ' ' << type.to_yaml_type
            end
          else
            self << ' !' << type.to_s
          end
        end
        @endl = false
      end

[Source]

# File lib/uttk/dumpers/Yaml.rb, line 112
      def up ( path )
        super
        @indent = @stack_indent.pop || ''
      end

[Validate]