mirror of
https://github.com/ruby/ruby.git
synced 2025-08-28 15:36:16 +02:00
* 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:
parent
6673f4e8af
commit
73af8137d9
4 changed files with 34 additions and 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>
|
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
|
||||||
|
|
19
ext/psych/lib/psych/json/ruby_events.rb
Normal file
19
ext/psych/lib/psych/json/ruby_events.rb
Normal 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
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue