1module Gem
2  if defined? ::Psych::Visitors
3    class NoAliasYAMLTree < Psych::Visitors::YAMLTree
4      def self.create
5        new({})
6      end unless respond_to? :create
7
8      def visit_String(str)
9        return super unless str == '=' # or whatever you want
10
11        quote = Psych::Nodes::Scalar::SINGLE_QUOTED
12        @emitter.scalar str, nil, nil, false, true, quote
13      end
14
15      # Noop this out so there are no anchors
16      def register(target, obj)
17      end
18
19      # This is ported over from the yaml_tree in 1.9.3
20      def format_time time
21        if time.utc?
22          time.strftime("%Y-%m-%d %H:%M:%S.%9N Z")
23        else
24          time.strftime("%Y-%m-%d %H:%M:%S.%9N %:z")
25        end
26      end
27
28      private :format_time
29    end
30  end
31end
32