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

ruby-changes:18907

From: tenderlove <ko1@a...>
Date: Mon, 21 Feb 2011 11:00:50 +0900 (JST)
Subject: [ruby-changes:18907] Ruby:r30932 (trunk): * ext/psych/lib/psych/json/yaml_events.rb: refactoring JSON event

tenderlove	2011-02-21 11:00:43 +0900 (Mon, 21 Feb 2011)

  New Revision: 30932

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

  Log:
    * ext/psych/lib/psych/json/yaml_events.rb: refactoring JSON event
      handling methods to a module for reuse.
    * ext/psych/lib/psych/json/tree_builder.rb: AST builder uses JSON
      event methods.
    * ext/psych/lib/psych/json/stream.rb: stream emitter uses JSON event
      methods.

  Added files:
    trunk/ext/psych/lib/psych/json/yaml_events.rb
  Modified files:
    trunk/ChangeLog
    trunk/ext/psych/lib/psych/json/stream.rb
    trunk/ext/psych/lib/psych/json/tree_builder.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 30931)
+++ ChangeLog	(revision 30932)
@@ -1,3 +1,12 @@
+Mon Feb 21 10:58:39 2011  Aaron Patterson <aaron@t...>
+
+	* ext/psych/lib/psych/json/yaml_events.rb: refactoring JSON event
+	  handling methods to a module for reuse.
+	* ext/psych/lib/psych/json/tree_builder.rb: AST builder uses JSON
+	  event methods.
+	* ext/psych/lib/psych/json/stream.rb: stream emitter uses JSON event
+	  methods.
+
 Mon Feb 21 10:54:29 2011  Aaron Patterson <aaron@t...>
 
 	* ext/psych/lib/psych/json/stream.rb: do not emit custom tags in maps
Index: ext/psych/lib/psych/json/tree_builder.rb
===================================================================
--- ext/psych/lib/psych/json/tree_builder.rb	(revision 30931)
+++ ext/psych/lib/psych/json/tree_builder.rb	(revision 30932)
@@ -1,3 +1,5 @@
+require 'psych/json/yaml_events'
+
 module Psych
   module JSON
     ###
@@ -4,29 +6,7 @@
     # Psych::JSON::TreeBuilder is an event based AST builder.  Events are sent
     # to an instance of Psych::JSON::TreeBuilder and a JSON AST is constructed.
     class TreeBuilder < Psych::TreeBuilder
-      def start_document version, tag_directives, implicit
-        super(version, tag_directives, !streaming?)
-      end
-
-      def end_document implicit_end = !streaming?
-        super(implicit_end)
-      end
-
-      def start_mapping anchor, tag, implicit, style
-        super(anchor, nil, implicit, Nodes::Mapping::FLOW)
-      end
-
-      def start_sequence anchor, tag, implicit, style
-        super(anchor, nil, implicit, Nodes::Sequence::FLOW)
-      end
-
-      def scalar value, anchor, tag, plain, quoted, style
-        if "tag:yaml.org,2002:null" == tag
-          super('null', nil, nil, true, false, Nodes::Scalar::PLAIN)
-        else
-          super
-        end
-      end
+      include Psych::JSON::YAMLEvents
     end
   end
 end
Index: ext/psych/lib/psych/json/yaml_events.rb
===================================================================
--- ext/psych/lib/psych/json/yaml_events.rb	(revision 0)
+++ ext/psych/lib/psych/json/yaml_events.rb	(revision 30932)
@@ -0,0 +1,29 @@
+module Psych
+  module JSON
+    module YAMLEvents # :nodoc:
+      def start_document version, tag_directives, implicit
+        super(version, tag_directives, !streaming?)
+      end
+
+      def end_document implicit_end = !streaming?
+        super(implicit_end)
+      end
+
+      def start_mapping anchor, tag, implicit, style
+        super(anchor, nil, implicit, Nodes::Mapping::FLOW)
+      end
+
+      def start_sequence anchor, tag, implicit, style
+        super(anchor, nil, implicit, Nodes::Sequence::FLOW)
+      end
+
+      def scalar value, anchor, tag, plain, quoted, style
+        if "tag:yaml.org,2002:null" == tag
+          super('null', nil, nil, true, false, Nodes::Scalar::PLAIN)
+        else
+          super
+        end
+      end
+    end
+  end
+end
Index: ext/psych/lib/psych/json/stream.rb
===================================================================
--- ext/psych/lib/psych/json/stream.rb	(revision 30931)
+++ ext/psych/lib/psych/json/stream.rb	(revision 30932)
@@ -1,4 +1,5 @@
 require 'psych/json/ruby_events'
+require 'psych/json/yaml_events'
 
 module Psych
   module JSON
@@ -6,25 +7,7 @@
       include Psych::JSON::RubyEvents
 
       class Emitter < Psych::Stream::Emitter # :nodoc:
-        def start_document version, tag_directives, implicit
-          super(version, tag_directives, !streaming?)
-        end
-
-        def start_mapping anchor, tag, implicit, style
-          super(anchor, nil, implicit, Nodes::Mapping::FLOW)
-        end
-
-        def start_sequence anchor, tag, implicit, style
-          super(anchor, nil, implicit, Nodes::Sequence::FLOW)
-        end
-
-        def scalar value, anchor, tag, plain, quoted, style
-          if "tag:yaml.org,2002:null" == tag
-            super('null', nil, nil, true, false, Nodes::Scalar::PLAIN)
-          else
-            super
-          end
-        end
+        include Psych::JSON::YAMLEvents
       end
     end
   end

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

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