diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2009-09-28 12:06:39 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2009-09-28 12:06:39 -0700 |
commit | 9f5da8f6aa0bfc3d59817de9d5c8a22000c0b9ce (patch) | |
tree | e14784f845736386b9535af1769d40a6845d0ce5 /lib | |
parent | f4e5e8205ee3b63403a6b6695746046cd663d6d8 (diff) | |
download | psych-9f5da8f6aa0bfc3d59817de9d5c8a22000c0b9ce.zip |
documents can convert to ruby
Diffstat (limited to 'lib')
-rw-r--r-- | lib/psych/handler.rb | 2 | ||||
-rw-r--r-- | lib/psych/nodes/document.rb | 9 | ||||
-rw-r--r-- | lib/psych/visitors/to_ruby.rb | 4 |
3 files changed, 13 insertions, 2 deletions
diff --git a/lib/psych/handler.rb b/lib/psych/handler.rb index 84ce4c2..f67a554 100644 --- a/lib/psych/handler.rb +++ b/lib/psych/handler.rb @@ -10,7 +10,7 @@ module Psych ### # Called when the document starts with the declared +version+, # +tag_directives+, if the document is +implicit+ - def start_document version = [], tag_directives = [], implicit = true + def start_document version, tag_directives, implicit end ### diff --git a/lib/psych/nodes/document.rb b/lib/psych/nodes/document.rb index 05eca82..0bd58b2 100644 --- a/lib/psych/nodes/document.rb +++ b/lib/psych/nodes/document.rb @@ -10,12 +10,19 @@ module Psych # Was this document implicitly created? attr_accessor :implicit - def initialize version, tag_directives, implicit + def initialize version = [], tag_directives = [], implicit = true super() @version = version @tag_directives = tag_directives @implicit = implicit end + + ### + # Returns the root node. A Document may only have one root node: + # http://yaml.org/spec/1.1/#id898031 + def root + children.first + end end end end diff --git a/lib/psych/visitors/to_ruby.rb b/lib/psych/visitors/to_ruby.rb index b82fc3c..a4e6152 100644 --- a/lib/psych/visitors/to_ruby.rb +++ b/lib/psych/visitors/to_ruby.rb @@ -14,6 +14,10 @@ module Psych visitor_for(Nodes::Mapping) do |o| Hash[*o.children.map { |c| c.accept self }] end + + visitor_for(Nodes::Document) do |o| + o.root.accept self + end end end end |