[前][次][番号順一覧][スレッド一覧]

ruby-changes:18904

From: tenderlove <ko1@a...>
Date: Mon, 21 Feb 2011 10:06:41 +0900 (JST)
Subject: [ruby-changes:18904] Ruby:r30929 (trunk): * ext/psych/lib/psych/json/ruby_events.rb: DRY up ruby event handling

tenderlove	2011-02-21 10:06:34 +0900 (Mon, 21 Feb 2011)

  New Revision: 30929

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=30929

  Log:
    * ext/psych/lib/psych/json/ruby_events.rb: DRY up ruby event handling
      for JSON.
    * ext/psych/lib/psych/visitors/json_tree.rb: use ruby events module
    * ext/psych/lib/psych/json/stream.rb: ditto

  Added files:
    trunk/ext/psych/lib/psych/json/ruby_events.rb
  Modified files:
    trunk/ChangeLog
    trunk/ext/psych/lib/psych/json/stream.rb
    trunk/ext/psych/lib/psych/visitors/json_tree.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 30928)
+++ ChangeLog	(revision 30929)
@@ -1,3 +1,10 @@
+Mon Feb 21 10:05:10 2011  Aaron Patterson <aaron@t...>
+
+	* ext/psych/lib/psych/json/ruby_events.rb: DRY up ruby event handling
+	  for JSON.
+	* ext/psych/lib/psych/visitors/json_tree.rb: use ruby events module
+	* ext/psych/lib/psych/json/stream.rb: ditto
+
 Mon Feb 21 10:01:01 2011  Aaron Patterson <aaron@t...>
 
 	* ext/psych/lib/psych/json/stream.rb: fix JSON stream emits to use
Index: ext/psych/lib/psych/visitors/json_tree.rb
===================================================================
--- ext/psych/lib/psych/visitors/json_tree.rb	(revision 30928)
+++ ext/psych/lib/psych/visitors/json_tree.rb	(revision 30929)
@@ -1,23 +1,13 @@
+require 'psych/json/ruby_events'
+
 module Psych
   module Visitors
     class JSONTree < YAMLTree
+      include Psych::JSON::RubyEvents
+
       def initialize options = {}, emitter = Psych::JSON::TreeBuilder.new
         super
       end
-
-      def visit_Time o
-        formatted = format_time o
-        @emitter.scalar formatted, nil, nil, false, true, Nodes::Scalar::DOUBLE_QUOTED
-      end
-
-      def visit_DateTime o
-        visit_Time o.to_time
-      end
-
-      def visit_String o
-        @emitter.scalar o.to_s, nil, nil, false, true, Nodes::Scalar::DOUBLE_QUOTED
-      end
-      alias :visit_Symbol :visit_String
     end
   end
 end
Index: ext/psych/lib/psych/json/ruby_events.rb
===================================================================
--- ext/psych/lib/psych/json/ruby_events.rb	(revision 0)
+++ ext/psych/lib/psych/json/ruby_events.rb	(revision 30929)
@@ -0,0 +1,19 @@
+module Psych
+  module JSON
+    module RubyEvents # :nodoc:
+      def visit_Time o
+        formatted = format_time o
+        @emitter.scalar formatted, nil, nil, false, true, Nodes::Scalar::DOUBLE_QUOTED
+      end
+
+      def visit_DateTime o
+        visit_Time o.to_time
+      end
+
+      def visit_String o
+        @emitter.scalar o.to_s, nil, nil, false, true, Nodes::Scalar::DOUBLE_QUOTED
+      end
+      alias :visit_Symbol :visit_String
+    end
+  end
+end

Property changes on: ext/psych/lib/psych/json/ruby_events.rb
___________________________________________________________________
Added: svn:eol-style
   + LF

Index: ext/psych/lib/psych/json/stream.rb
===================================================================
--- ext/psych/lib/psych/json/stream.rb	(revision 30928)
+++ ext/psych/lib/psych/json/stream.rb	(revision 30929)
@@ -1,6 +1,10 @@
+require 'psych/json/ruby_events'
+
 module Psych
   module JSON
     class Stream < Psych::Stream
+      include Psych::JSON::RubyEvents
+
       class Emitter < Psych::Stream::Emitter # :nodoc:
         def start_document version, tag_directives, implicit
           super(version, tag_directives, !streaming?)
@@ -22,20 +26,6 @@
           end
         end
       end
-
-      def visit_Time o
-        formatted = format_time o
-        @emitter.scalar formatted, nil, nil, false, true, Nodes::Scalar::DOUBLE_QUOTED
-      end
-
-      def visit_DateTime o
-        visit_Time o.to_time
-      end
-
-      def visit_String o
-        @emitter.scalar o.to_s, nil, nil, false, true, Nodes::Scalar::DOUBLE_QUOTED
-      end
-      alias :visit_Symbol :visit_String
     end
   end
 end

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]