[#29911] [Bug #3231] Digest Does Not Build — Charlie Savage <redmine@...>

Bug #3231: Digest Does Not Build

19 messages 2010/05/01

[#29920] [Feature #3232] Loops (while/until) should return last statement value if any, like if/unless — Benoit Daloze <redmine@...>

Feature #3232: Loops (while/until) should return last statement value if any, like if/unless

9 messages 2010/05/01

[#29997] years in Time.utc — Xavier Noria <fxn@...>

Does anyone have a precise statement about the years supported by

13 messages 2010/05/04

[#30010] [Bug #3248] extension 'tk' is finding tclConfig.sh and tkConfig.sh incorrectly — Luis Lavena <redmine@...>

Bug #3248: extension 'tk' is finding tclConfig.sh and tkConfig.sh incorrectly

9 messages 2010/05/05

[#30226] [Bug #3288] Segmentation fault - activesupport-3.0.0.beta3/lib/active_support/callbacks.rb:88 — Szymon Jeż <redmine@...>

Bug #3288: Segmentation fault - activesupport-3.0.0.beta3/lib/active_support/callbacks.rb:88

10 messages 2010/05/13

[#30358] tk doesn't startup well in doze — Roger Pack <rogerdpack2@...>

Currently with 1.9.x and tk 8.5,the following occurs

12 messages 2010/05/22

[ruby-core:29993] [Feature:trunk] thread-local yamler

From: Nobuyoshi Nakada <nobu@...>
Date: 2010-05-04 07:35:59 UTC
List: ruby-core #29993
Hi,

Currently, YAML.yamler= has an effect on the whole process.
What about making it thread-local?


diff --git a/lib/yaml.rb b/lib/yaml.rb
index 9b5a9b2..236489b 100644
--- a/lib/yaml.rb
+++ b/lib/yaml.rb
@@ -1,43 +1,68 @@
 module YAML
-  class EngineManager # :nodoc:
-    attr_reader :yamler
+  class << self
+    def engine
+      ::Thread.current[:yamler] or
+        (ENGINE.yamler = ENGINE.default; ::Thread.current[:yamler])
+    end
 
-    def initialize
-      @yamler = nil
+    def const_defined?(name)
+      engine.const_defined?(name)
     end
 
-    def syck?
-      'syck' == @yamler
+    def const_get(name)
+      engine = self.engine
+      begin
+        engine.const_get(name)
+      rescue NameError => e
+        raise NameError, "uninitialized constant #{self}::#{name}", caller(2)
+      end
     end
 
-    def yamler= engine
-      raise(ArgumentError, "bad engine") unless %w{syck psych}.include?(engine)
+    alias const_missing const_get
 
-      require engine
+    def method_missing(name, *args, &block)
+      engine.__send__(name, *args, &block)
+    end
 
-      Object.class_eval <<-eorb, __FILE__, __LINE__ + 1
-        remove_const 'YAML'
-        YAML = #{engine.capitalize}
-        remove_method :to_yaml
-        alias :to_yaml :#{engine}_to_yaml
-      eorb
+    def respond_to_missing?(name)
+      engine.respond_to?(name)
+    end
+
+  private
+
+    def extend_object(obj)
+      engine.__send__(:extend_object, obj)
+    end
 
-      @yamler = engine
-      engine
+    def append_features(mod)
+      engine.__send__(:append_features, mod)
     end
   end
 
-  ENGINE = YAML::EngineManager.new
-end
+  class << (ENGINE = Object.new) # :nodoc:
+    def default
+      !defined?(Syck) && defined?(Psych) ? 'psych' : 'syck'
+    end
 
-engine = (!defined?(Syck) && defined?(Psych) ? 'psych' : 'syck')
+    def yamler
+      if engine = YAML.engine
+        engine.name.downcase
+      else
+        default
+      end
+    end
 
-module Syck
-  ENGINE = YAML::ENGINE
-end
+    def syck?
+      'syck' == yamler
+    end
 
-module Psych
-  ENGINE = YAML::ENGINE
-end
+    def yamler= engine
+      raise(ArgumentError, "bad engine") unless %w{syck psych}.include?(engine)
+      require engine
+      engine = ::Object.const_get(engine.capitalize)
+      ::Thread.current[:yamler] = engine
+    end
+  end
 
-YAML::ENGINE.yamler = engine
+  ENGINE.freeze
+end


-- 
Nobu Nakada

In This Thread

Prev Next