diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-03-22 19:41:47 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-03-22 19:41:47 -0700 |
commit | 4110ae48f57b1eaa6e8caeffaf5a70f1e32f6973 (patch) | |
tree | 9b28bf07915a51128778787007961dfdf83761dd /lib | |
parent | 9c46c5b60e9554da08109887684704fc8b7b3a4e (diff) | |
download | psych-4110ae48f57b1eaa6e8caeffaf5a70f1e32f6973.zip |
testing parse_file
Diffstat (limited to 'lib')
-rw-r--r-- | lib/psych.rb | 16 | ||||
-rw-r--r-- | lib/psych/visitors/to_ruby.rb | 4 | ||||
-rw-r--r-- | lib/psych/yaml.rb | 4 |
3 files changed, 19 insertions, 5 deletions
diff --git a/lib/psych.rb b/lib/psych.rb index d244ddf..b7e5545 100644 --- a/lib/psych.rb +++ b/lib/psych.rb @@ -117,6 +117,20 @@ module Psych end ### + # Parse a file at +filename+. Returns the YAML AST. + def self.parse_file filename + File.open filename do |f| + parse f + end + end + + ### + # Returns a default parser + def self.parser + Psych::Parser.new(TreeBuilder.new) + end + + ### # Parse a YAML string in +yaml+. Returns the full AST for the YAML document. # This method can handle multiple YAML documents contained in +yaml+. # @@ -126,7 +140,7 @@ module Psych # # See Psych::Nodes for more information about YAML AST. def self.yaml_ast yaml - parser = Psych::Parser.new(TreeBuilder.new) + parser = self.parser parser.parse yaml parser.handler.root end diff --git a/lib/psych/visitors/to_ruby.rb b/lib/psych/visitors/to_ruby.rb index c98fa01..1289ff9 100644 --- a/lib/psych/visitors/to_ruby.rb +++ b/lib/psych/visitors/to_ruby.rb @@ -9,12 +9,12 @@ module Psych super @st = {} @ss = ScalarScanner.new + @domain_types = Psych.domain_types end def accept target result = super - return result unless target.tag - return result if Psych.domain_types.empty? + return result if @domain_types.empty? || !target.tag short_name = target.tag.sub(/^!/, '').split('/', 2).last if Psych.domain_types.key? short_name diff --git a/lib/psych/yaml.rb b/lib/psych/yaml.rb index 91cdfba..49380eb 100644 --- a/lib/psych/yaml.rb +++ b/lib/psych/yaml.rb @@ -10,8 +10,8 @@ YAML = Psych end class Object - def self.yaml_tag name - Psych.add_tag(name, self) + def self.yaml_tag url + Psych.add_tag(url, self) end def to_yaml options = {} |