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