summaryrefslogtreecommitdiff
path: root/lib/psych.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-03-22 21:15:02 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2010-03-22 21:15:02 -0700
commit668fbbe73c6706b40060f457418b8045c16a667b (patch)
treeb292723926ec75c032c721eebcf40aef8ba1f0b4 /lib/psych.rb
parent3e0c5df3134f2a28822c267aa55916322750b42a (diff)
downloadpsych-668fbbe73c6706b40060f457418b8045c16a667b.zip
adding more syck compatible methods
Diffstat (limited to 'lib/psych.rb')
-rw-r--r--lib/psych.rb18
1 files changed, 13 insertions, 5 deletions
diff --git a/lib/psych.rb b/lib/psych.rb
index 9dfc26e..e53ced2 100644
--- a/lib/psych.rb
+++ b/lib/psych.rb
@@ -46,7 +46,7 @@ require 'psych/yaml'
#
# Psych provides access to an AST produced from parsing a YAML document. This
# tree is built using the Psych::Parser and Psych::TreeBuilder. The AST can
-# be examined and manipulated freely. Please see Psych::yaml_ast,
+# be examined and manipulated freely. Please see Psych::parse_stream,
# Psych::Nodes, and Psych::Nodes::Node for more information on dealing with
# YAML syntax trees.
#
@@ -113,7 +113,7 @@ module Psych
#
# See Psych::Nodes for more information about YAML AST.
def self.parse yaml
- yaml_ast(yaml).children.first.children.first
+ parse_stream(yaml).children.first.children.first
end
###
@@ -139,12 +139,17 @@ module Psych
# Psych.load("---\n - a\n - b") # => #<Psych::Nodes::Stream:0x00>
#
# See Psych::Nodes for more information about YAML AST.
- def self.yaml_ast yaml
+ def self.parse_stream yaml
parser = self.parser
parser.parse yaml
parser.handler.root
end
+ def self.load_stream yaml # :nodoc:
+ warn "#{caller[0]}: load_stream is deprecated, use parse_stream"
+ parse_stream yaml
+ end
+
###
# Dump Ruby object +o+ to a YAML string using +options+.
#
@@ -172,9 +177,12 @@ module Psych
# Psych.load_documents("--- foo\n...\n--- bar\n...") # => ['foo', 'bar']
#
def self.load_documents yaml, &block
- list = yaml_ast(yaml).children.map { |child| child.to_ruby }
+ list = parse_stream(yaml).children.map { |child| child.to_ruby }
+
return list unless block_given?
- warn "#{caller[0]}: calling load_documents with a block is deprecated"
+ if $VERBOSE
+ warn "#{caller[0]}: calling load_documents with a block is deprecated"
+ end
list.each(&block)
end