From 5d83d5982f411c8c5df0bd3aa11ebd2574a406a1 Mon Sep 17 00:00:00 2001 From: Jon Guymon Date: Mon, 15 Aug 2011 23:09:31 -0700 Subject: [PATCH] return yamler to original state after fussing with it --- lib/new_relic/control/instance_methods.rb | 11 +++++++++-- lib/new_relic/language_support.rb | 19 ++++++++++++++++++- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/lib/new_relic/control/instance_methods.rb b/lib/new_relic/control/instance_methods.rb index 90a92ad8da..d3ea2adb80 100644 --- a/lib/new_relic/control/instance_methods.rb +++ b/lib/new_relic/control/instance_methods.rb @@ -1,5 +1,9 @@ +require 'new_relic/language_support' + module NewRelic class Control + include NewRelic::LanguageSupport::Control + # Contains methods that relate to the runtime usage of the control # object. Note that these are subject to override in the # NewRelic::Control::Framework classes that are actually instantiated @@ -147,8 +151,7 @@ def initialize local_env, config_file_override=nil puts "Cannot find or read #{newrelic_file}" @yaml = {} else - YAML::ENGINE.yamler = 'syck' if defined?(YAML::ENGINE) - @yaml = YAML.load(ERB.new(File.read(newrelic_file)).result(binding)) + @yaml = load_newrelic_yml(newrelic_file, binding) end rescue ScriptError, StandardError => e puts e @@ -156,6 +159,10 @@ def initialize local_env, config_file_override=nil raise "Error reading newrelic.yml file: #{e}" end + def load_newrelic_yml(path, binding) + YAML.load(ERB.new(File.read(path)).result(binding)) + end + def root '.' end diff --git a/lib/new_relic/language_support.rb b/lib/new_relic/language_support.rb index 81101aa8a2..631ae8f2ad 100644 --- a/lib/new_relic/language_support.rb +++ b/lib/new_relic/language_support.rb @@ -14,7 +14,24 @@ def self.load(*args) end end end - + + module Control + def self.included(base) + # need to use syck rather than psych when possible + if defined?(::YAML::ENGINE) + base.class_eval do + def load_newrelic_yml(*args) + yamler = ::YAML::ENGINE.yamler + ::YAML::ENGINE.yamler = 'syck' + val = super + ::YAML::ENGINE.yamler = yamler + val + end + end + end + end + end + module SynchronizedHash def self.included(base) # need to lock iteration of stats hash in 1.9.x