* 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

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30929 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
tenderlove 2011-02-21 01:06:34 +00:00
parent 6673f4e8af
commit 73af8137d9
4 changed files with 34 additions and 28 deletions

View file

@ -1,3 +1,10 @@
Mon Feb 21 10:05:10 2011 Aaron Patterson <aaron@tenderlovemaking.com>
* 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@tenderlovemaking.com> Mon Feb 21 10:01:01 2011 Aaron Patterson <aaron@tenderlovemaking.com>
* ext/psych/lib/psych/json/stream.rb: fix JSON stream emits to use * ext/psych/lib/psych/json/stream.rb: fix JSON stream emits to use

View file

@ -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

View file

@ -1,6 +1,10 @@
require 'psych/json/ruby_events'
module Psych module Psych
module JSON module JSON
class Stream < Psych::Stream class Stream < Psych::Stream
include Psych::JSON::RubyEvents
class Emitter < Psych::Stream::Emitter # :nodoc: class Emitter < Psych::Stream::Emitter # :nodoc:
def start_document version, tag_directives, implicit def start_document version, tag_directives, implicit
super(version, tag_directives, !streaming?) super(version, tag_directives, !streaming?)
@ -22,20 +26,6 @@ module Psych
end end
end 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 end
end end

View file

@ -1,23 +1,13 @@
require 'psych/json/ruby_events'
module Psych module Psych
module Visitors module Visitors
class JSONTree < YAMLTree class JSONTree < YAMLTree
include Psych::JSON::RubyEvents
def initialize options = {}, emitter = Psych::JSON::TreeBuilder.new def initialize options = {}, emitter = Psych::JSON::TreeBuilder.new
super super
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 end
end end