diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2009-10-08 21:12:48 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2009-10-08 21:12:48 -0700 |
commit | 4d6d48b119cf62fb01f54730e9efcf76b8ab351a (patch) | |
tree | 89427eba988dac667cfe0a81bc89809f7ba0712c /lib | |
parent | 6f5fcb7d4e7388f2ba78f3b0b6b35563fd11135a (diff) | |
download | psych-4d6d48b119cf62fb01f54730e9efcf76b8ab351a.zip |
supporting add_domain_ype syntax
Diffstat (limited to 'lib')
-rw-r--r-- | lib/psych.rb | 6 | ||||
-rw-r--r-- | lib/psych/visitors/to_ruby.rb | 14 |
2 files changed, 20 insertions, 0 deletions
diff --git a/lib/psych.rb b/lib/psych.rb index f1ee542..9250a2c 100644 --- a/lib/psych.rb +++ b/lib/psych.rb @@ -54,4 +54,10 @@ module Psych block.call child.to_ruby end end + + @domain_types = {} + def self.add_domain_type domain, type_tag, &block + @domain_types[type_tag] = [domain, block] + end + class << self; attr_accessor :domain_types; end end diff --git a/lib/psych/visitors/to_ruby.rb b/lib/psych/visitors/to_ruby.rb index d4d6ac5..f6a4d69 100644 --- a/lib/psych/visitors/to_ruby.rb +++ b/lib/psych/visitors/to_ruby.rb @@ -10,6 +10,20 @@ module Psych @st = {} end + def accept target + result = super + return result if Psych.domain_types.empty? + + if target.respond_to?(:tag) && target.tag + short_name = target.tag.sub(/^!/, '').split('/').last + if Psych.domain_types.key? short_name + url, block = Psych.domain_types[short_name] + block.call "http://#{url}:#{short_name}", result + end + end + result + end + def visit_Psych_Nodes_Scalar o @st[o.anchor] = o.value if o.anchor |