diff options
author | tenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-02-21 01:06:34 +0000 |
---|---|---|
committer | tenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-02-21 01:06:34 +0000 |
commit | 73af8137d9df0ef0bbdf49c4744242f727ed227f (patch) | |
tree | f8e648ca8a4708ddd2caa06f5a4cf415ae4121e2 | |
parent | 6673f4e8afb9d468849bcc7d87c82c46c799f119 (diff) | |
download | ruby-73af8137d9df0ef0bbdf49c4744242f727ed227f.tar.gz |
* 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
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | ext/psych/lib/psych/json/ruby_events.rb | 19 | ||||
-rw-r--r-- | ext/psych/lib/psych/json/stream.rb | 18 | ||||
-rw-r--r-- | ext/psych/lib/psych/visitors/json_tree.rb | 18 |
4 files changed, 34 insertions, 28 deletions
@@ -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> * ext/psych/lib/psych/json/stream.rb: fix JSON stream emits to use diff --git a/ext/psych/lib/psych/json/ruby_events.rb b/ext/psych/lib/psych/json/ruby_events.rb new file mode 100644 index 0000000000..6b73249c06 --- /dev/null +++ b/ext/psych/lib/psych/json/ruby_events.rb @@ -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 diff --git a/ext/psych/lib/psych/json/stream.rb b/ext/psych/lib/psych/json/stream.rb index b240b6cbdb..60c458ad38 100644 --- a/ext/psych/lib/psych/json/stream.rb +++ b/ext/psych/lib/psych/json/stream.rb @@ -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 @@ module Psych 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 diff --git a/ext/psych/lib/psych/visitors/json_tree.rb b/ext/psych/lib/psych/visitors/json_tree.rb index dd06e80607..292afae623 100644 --- a/ext/psych/lib/psych/visitors/json_tree.rb +++ b/ext/psych/lib/psych/visitors/json_tree.rb @@ -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 |