Sha256: e5747d6471eb7703f40926e56a06b83f23b2e9934b414f75eceb88420c60bd7f

Contents?: true

Size: 1008 Bytes

Versions: 26

Compression:

Stored size: 1008 Bytes

Contents

require 'psych'

module TreasureData
  module CompactFormatYamler
    module Visitors
      class YAMLTree < Psych::Visitors::YAMLTree
        # NOTE support 2.0 following
        unless self.respond_to? :create
          class << self
            alias :create :new
          end
        end

        def visit_Hash o
          if o.class == ::Hash && o.values.all? {|v| v.kind_of?(Numeric) || v.kind_of?(String) || v.kind_of?(Symbol) }
            register(o, @emitter.start_mapping(nil, nil, true, Psych::Nodes::Mapping::FLOW))

            o.each do |k,v|
              accept k
              accept v
            end
            @emitter.end_mapping
          else
            super
          end
        end
      end
    end

    def self.dump(o, io = nil, options = {})
      if Hash === io
        options = io
        io = nil
      end

      visitor = ::TreasureData::CompactFormatYamler::Visitors::YAMLTree.create options
      visitor << o
      visitor.tree.yaml io, options
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
td-0.17.1 lib/td/compact_format_yamler.rb
td-0.17.0 lib/td/compact_format_yamler.rb
td-0.16.10 lib/td/compact_format_yamler.rb
td-0.16.9 lib/td/compact_format_yamler.rb
td-0.16.8 lib/td/compact_format_yamler.rb
td-0.16.7 lib/td/compact_format_yamler.rb
td-0.16.6 lib/td/compact_format_yamler.rb
td-0.16.5 lib/td/compact_format_yamler.rb
td-0.16.4 lib/td/compact_format_yamler.rb
td-0.16.3 lib/td/compact_format_yamler.rb
td-0.16.1 lib/td/compact_format_yamler.rb
td-0.16.0 lib/td/compact_format_yamler.rb
td-0.15.9 lib/td/compact_format_yamler.rb
td-0.15.8 lib/td/compact_format_yamler.rb
td-0.15.7 lib/td/compact_format_yamler.rb
td-0.15.6 lib/td/compact_format_yamler.rb
td-0.15.5 lib/td/compact_format_yamler.rb
td-0.15.4 lib/td/compact_format_yamler.rb
td-0.15.3 lib/td/compact_format_yamler.rb
td-0.15.2 lib/td/compact_format_yamler.rb