ruby-changes:18911
From: tenderlove <ko1@a...>
Date: Tue, 22 Feb 2011 03:09:47 +0900 (JST)
Subject: [ruby-changes:18911] Ruby:r30936 (trunk): * ext/psych/lib/psych/streaming.rb: refactor streaming methods to a
tenderlove 2011-02-22 03:09:38 +0900 (Tue, 22 Feb 2011) New Revision: 30936 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=30936 Log: * ext/psych/lib/psych/streaming.rb: refactor streaming methods to a module. * ext/psych/lib/psych/stream.rb: extracted streaming specific methods to a module. * ext/psych/lib/psych/json/stream.rb: JSON stream inherits from JSONTree and includes streaming methods. * ext/psych/lib/psych/visitors/json_tree.rb: JSON does not support object references, so remove object reference testing when building JSON trees. Added files: trunk/ext/psych/lib/psych/streaming.rb Modified files: trunk/ChangeLog trunk/ext/psych/lib/psych/json/stream.rb trunk/ext/psych/lib/psych/stream.rb trunk/ext/psych/lib/psych/visitors/json_tree.rb trunk/ext/psych/lib/psych.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 30935) +++ ChangeLog (revision 30936) @@ -1,3 +1,15 @@ +Tue Feb 22 03:04:46 2011 Aaron Patterson <aaron@t...> + + * ext/psych/lib/psych/streaming.rb: refactor streaming methods to a + module. + * ext/psych/lib/psych/stream.rb: extracted streaming specific methods + to a module. + * ext/psych/lib/psych/json/stream.rb: JSON stream inherits from + JSONTree and includes streaming methods. + * ext/psych/lib/psych/visitors/json_tree.rb: JSON does not support + object references, so remove object reference testing when building + JSON trees. + Tue Feb 22 02:41:51 2011 Aaron Patterson <aaron@t...> * ext/psych/lib/psych/visitors/yaml_tree.rb (accept): use Hash#key? Index: ext/psych/lib/psych/visitors/json_tree.rb =================================================================== --- ext/psych/lib/psych/visitors/json_tree.rb (revision 30935) +++ ext/psych/lib/psych/visitors/json_tree.rb (revision 30936) @@ -8,6 +8,14 @@ def initialize options = {}, emitter = Psych::JSON::TreeBuilder.new super end + + def accept target + if target.respond_to?(:encode_with) + dump_coder target + else + send(@dispatch_cache[target.class], target) + end + end end end end Index: ext/psych/lib/psych/streaming.rb =================================================================== --- ext/psych/lib/psych/streaming.rb (revision 0) +++ ext/psych/lib/psych/streaming.rb (revision 30936) @@ -0,0 +1,22 @@ +module Psych + module Streaming + ### + # Create a new streaming emitter. Emitter will print to +io+. See + # Psych::Stream for an example. + def initialize io + super({}, self.class.const_get(:Emitter).new(io)) + end + + ### + # Start streaming using +encoding+ + def start encoding = Nodes::Stream::UTF8 + super.tap { yield self if block_given? } + ensure + finish if block_given? + end + + private + def register target, obj + end + end +end Index: ext/psych/lib/psych/stream.rb =================================================================== --- ext/psych/lib/psych/stream.rb (revision 30935) +++ ext/psych/lib/psych/stream.rb (revision 30936) @@ -31,23 +31,6 @@ end end - ### - # Create a new streaming emitter. Emitter will print to +io+. See - # Psych::Stream for an example. - def initialize io - super({}, self.class.const_get(:Emitter).new(io)) - end - - ### - # Start streaming using +encoding+ - def start encoding = Nodes::Stream::UTF8 - super.tap { yield self if block_given? } - ensure - finish if block_given? - end - - private - def register target, obj - end + include Psych::Streaming end end Index: ext/psych/lib/psych/json/stream.rb =================================================================== --- ext/psych/lib/psych/json/stream.rb (revision 30935) +++ ext/psych/lib/psych/json/stream.rb (revision 30936) @@ -3,8 +3,9 @@ module Psych module JSON - class Stream < Psych::Stream + class Stream < Psych::Visitors::JSONTree include Psych::JSON::RubyEvents + include Psych::Streaming class Emitter < Psych::Stream::Emitter # :nodoc: include Psych::JSON::YAMLEvents Index: ext/psych/lib/psych.rb =================================================================== --- ext/psych/lib/psych.rb (revision 30935) +++ ext/psych/lib/psych.rb (revision 30936) @@ -1,5 +1,6 @@ require 'psych.so' require 'psych/nodes' +require 'psych/streaming' require 'psych/visitors' require 'psych/handler' require 'psych/tree_builder' -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/