mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30936 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
10ec858f40
commit
4ed82ae5cb
6 changed files with 46 additions and 19 deletions
12
ChangeLog
12
ChangeLog
|
@ -1,3 +1,15 @@
|
||||||
|
Tue Feb 22 03:04:46 2011 Aaron Patterson <aaron@tenderlovemaking.com>
|
||||||
|
|
||||||
|
* 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@tenderlovemaking.com>
|
Tue Feb 22 02:41:51 2011 Aaron Patterson <aaron@tenderlovemaking.com>
|
||||||
|
|
||||||
* ext/psych/lib/psych/visitors/yaml_tree.rb (accept): use Hash#key?
|
* ext/psych/lib/psych/visitors/yaml_tree.rb (accept): use Hash#key?
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
require 'psych.so'
|
require 'psych.so'
|
||||||
require 'psych/nodes'
|
require 'psych/nodes'
|
||||||
|
require 'psych/streaming'
|
||||||
require 'psych/visitors'
|
require 'psych/visitors'
|
||||||
require 'psych/handler'
|
require 'psych/handler'
|
||||||
require 'psych/tree_builder'
|
require 'psych/tree_builder'
|
||||||
|
|
|
@ -3,8 +3,9 @@ require 'psych/json/yaml_events'
|
||||||
|
|
||||||
module Psych
|
module Psych
|
||||||
module JSON
|
module JSON
|
||||||
class Stream < Psych::Stream
|
class Stream < Psych::Visitors::JSONTree
|
||||||
include Psych::JSON::RubyEvents
|
include Psych::JSON::RubyEvents
|
||||||
|
include Psych::Streaming
|
||||||
|
|
||||||
class Emitter < Psych::Stream::Emitter # :nodoc:
|
class Emitter < Psych::Stream::Emitter # :nodoc:
|
||||||
include Psych::JSON::YAMLEvents
|
include Psych::JSON::YAMLEvents
|
||||||
|
|
|
@ -31,23 +31,6 @@ module Psych
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
###
|
include Psych::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
|
||||||
end
|
end
|
||||||
|
|
22
ext/psych/lib/psych/streaming.rb
Normal file
22
ext/psych/lib/psych/streaming.rb
Normal file
|
@ -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
|
|
@ -8,6 +8,14 @@ module Psych
|
||||||
def initialize options = {}, emitter = Psych::JSON::TreeBuilder.new
|
def initialize options = {}, emitter = Psych::JSON::TreeBuilder.new
|
||||||
super
|
super
|
||||||
end
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue