diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2009-09-30 16:07:42 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2009-09-30 16:07:42 -0700 |
commit | aeda4bb2ae215a67f862edb36f52f50358258278 (patch) | |
tree | 04c13400b240d636213ee4d49ef25538f3d3536a /lib | |
parent | 9306ea64be1a720a3f237e885137e1689ef054d0 (diff) | |
download | psych-aeda4bb2ae215a67f862edb36f52f50358258278.zip |
moving boolean classes
Diffstat (limited to 'lib')
-rw-r--r-- | lib/psych/ruby.rb | 5 | ||||
-rw-r--r-- | lib/psych/scalar_scanner.rb | 4 | ||||
-rw-r--r-- | lib/psych/visitors/to_ruby.rb | 7 | ||||
-rw-r--r-- | lib/psych/visitors/yast_builder.rb | 18 |
4 files changed, 31 insertions, 3 deletions
diff --git a/lib/psych/ruby.rb b/lib/psych/ruby.rb index 02d5531..255f73c 100644 --- a/lib/psych/ruby.rb +++ b/lib/psych/ruby.rb @@ -1,4 +1,7 @@ -[Object, String, Class, Hash, Array, NilClass, Float].each do |klass| +[ + Object, String, Class, Hash, Array, NilClass, Float, + FalseClass, TrueClass +].each do |klass| klass.send(:remove_method, :to_yaml) rescue NameError end diff --git a/lib/psych/scalar_scanner.rb b/lib/psych/scalar_scanner.rb index 20f694d..71c75e3 100644 --- a/lib/psych/scalar_scanner.rb +++ b/lib/psych/scalar_scanner.rb @@ -20,6 +20,10 @@ module Psych [:NAN, 0.0 / 0.0] when /^(null|~)$/i [:NULL, nil] + when /^(y|yes|true|on)$/i + [:BOOLEAN, true] + when /^(n|no|false|off)$/i + [:BOOLEAN, false] when /^:/i [:SYMBOL, @string.sub(/^:/, '').to_sym] when /^[-+]?[1-9][0-9_]*(:[0-5]?[0-9])+$/ diff --git a/lib/psych/visitors/to_ruby.rb b/lib/psych/visitors/to_ruby.rb index 34e0442..b05b34b 100644 --- a/lib/psych/visitors/to_ruby.rb +++ b/lib/psych/visitors/to_ruby.rb @@ -27,7 +27,12 @@ module Psych end def visit_Psych_Nodes_Mapping o - Hash[*o.children.map { |c| c.accept self }] + hash = {} + @st[o.anchor] = hash if o.anchor + o.children.map { |c| c.accept self }.each_slice(2) { |k,v| + hash[k] = v + } + hash end def visit_Psych_Nodes_Document o diff --git a/lib/psych/visitors/yast_builder.rb b/lib/psych/visitors/yast_builder.rb index 5dd7dc5..25cfe34 100644 --- a/lib/psych/visitors/yast_builder.rb +++ b/lib/psych/visitors/yast_builder.rb @@ -25,6 +25,14 @@ module Psych append Nodes::Scalar.new o.to_s end + def visit_TrueClass o + append Nodes::Scalar.new o.to_s + end + + def visit_FalseClass o + append Nodes::Scalar.new o.to_s + end + def visit_Float o if o.nan? append Nodes::Scalar.new '.nan' @@ -47,7 +55,15 @@ module Psych end def visit_Hash o - @stack.push append Nodes::Mapping.new + if node = @st[o.object_id] + node.anchor = o.object_id.to_s + return append Nodes::Alias.new o.object_id.to_s + end + + map = Nodes::Mapping.new + @st[o.object_id] = map + + @stack.push append map o.each do |k,v| k.accept self |