2003-05-09 17:25:50 -04:00
|
|
|
module YAML
|
2010-04-03 17:50:47 -04:00
|
|
|
class EngineManager # :nodoc:
|
|
|
|
attr_reader :yamler
|
2003-05-09 17:25:50 -04:00
|
|
|
|
2010-04-03 17:50:47 -04:00
|
|
|
def initialize
|
|
|
|
@yamler = nil
|
2004-07-15 01:04:49 -04:00
|
|
|
end
|
|
|
|
|
2010-04-03 17:50:47 -04:00
|
|
|
def syck?
|
|
|
|
'syck' == @yamler
|
2003-05-09 17:25:50 -04:00
|
|
|
end
|
|
|
|
|
2010-04-03 17:50:47 -04:00
|
|
|
def yamler= engine
|
|
|
|
raise(ArgumentError, "bad engine") unless %w{syck psych}.include?(engine)
|
2003-05-09 17:25:50 -04:00
|
|
|
|
2010-04-03 17:50:47 -04:00
|
|
|
require engine
|
2003-05-09 17:25:50 -04:00
|
|
|
|
2010-04-03 17:50:47 -04:00
|
|
|
Object.class_eval <<-eorb, __FILE__, __LINE__ + 1
|
|
|
|
remove_const 'YAML'
|
|
|
|
YAML = #{engine.capitalize}
|
|
|
|
remove_method :to_yaml
|
|
|
|
alias :to_yaml :#{engine}_to_yaml
|
|
|
|
eorb
|
2010-04-07 22:32:06 -04:00
|
|
|
|
|
|
|
@yamler = engine
|
2010-04-03 17:50:47 -04:00
|
|
|
engine
|
2003-05-09 17:25:50 -04:00
|
|
|
end
|
2010-04-03 17:50:47 -04:00
|
|
|
end
|
2003-05-09 17:25:50 -04:00
|
|
|
|
2010-04-03 17:50:47 -04:00
|
|
|
ENGINE = YAML::EngineManager.new
|
2003-05-09 17:25:50 -04:00
|
|
|
end
|
|
|
|
|
2010-04-07 22:45:23 -04:00
|
|
|
engine = (!defined?(Syck) && defined?(Psych) ? 'psych' : 'syck')
|
|
|
|
|
2010-04-03 17:50:47 -04:00
|
|
|
module Syck
|
|
|
|
ENGINE = YAML::ENGINE
|
2003-05-09 17:25:50 -04:00
|
|
|
end
|
|
|
|
|
2010-04-03 17:50:47 -04:00
|
|
|
module Psych
|
|
|
|
ENGINE = YAML::ENGINE
|
|
|
|
end
|
2003-05-09 17:25:50 -04:00
|
|
|
|
2010-04-07 22:45:23 -04:00
|
|
|
YAML::ENGINE.yamler = engine
|