2003-05-10 01:25:50 +04:00
|
|
|
module YAML
|
2010-04-04 01:50:47 +04:00
|
|
|
class EngineManager # :nodoc:
|
|
|
|
attr_reader :yamler
|
2003-05-10 01:25:50 +04:00
|
|
|
|
2010-04-04 01:50:47 +04:00
|
|
|
def initialize
|
|
|
|
@yamler = nil
|
2004-07-15 09:04:49 +04:00
|
|
|
end
|
|
|
|
|
2010-04-04 01:50:47 +04:00
|
|
|
def syck?
|
|
|
|
'syck' == @yamler
|
2003-05-10 01:25:50 +04:00
|
|
|
end
|
|
|
|
|
2010-04-04 01:50:47 +04:00
|
|
|
def yamler= engine
|
|
|
|
raise(ArgumentError, "bad engine") unless %w{syck psych}.include?(engine)
|
2003-05-10 01:25:50 +04:00
|
|
|
|
2010-04-04 01:50:47 +04:00
|
|
|
require engine
|
2003-05-10 01:25:50 +04:00
|
|
|
|
2010-04-04 01: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-08 06:32:06 +04:00
|
|
|
|
|
|
|
@yamler = engine
|
2010-04-04 01:50:47 +04:00
|
|
|
engine
|
2003-05-10 01:25:50 +04:00
|
|
|
end
|
2010-04-04 01:50:47 +04:00
|
|
|
end
|
2003-05-10 01:25:50 +04:00
|
|
|
|
2010-04-04 01:50:47 +04:00
|
|
|
ENGINE = YAML::EngineManager.new
|
2003-05-10 01:25:50 +04:00
|
|
|
end
|
|
|
|
|
2010-04-08 06:45:23 +04:00
|
|
|
engine = (!defined?(Syck) && defined?(Psych) ? 'psych' : 'syck')
|
|
|
|
|
2010-04-04 01:50:47 +04:00
|
|
|
module Syck
|
|
|
|
ENGINE = YAML::ENGINE
|
2003-05-10 01:25:50 +04:00
|
|
|
end
|
|
|
|
|
2010-04-04 01:50:47 +04:00
|
|
|
module Psych
|
|
|
|
ENGINE = YAML::ENGINE
|
|
|
|
end
|
2003-05-10 01:25:50 +04:00
|
|
|
|
2010-04-08 06:45:23 +04:00
|
|
|
YAML::ENGINE.yamler = engine
|