jm / toml

Parse TOML. Like a bawss.
MIT License
151 stars 38 forks source link

Array of table doesn't work #31

Closed owenthereal closed 9 years ago

owenthereal commented 10 years ago

Trying to convert an array of table and an error was raised:

irb(main):001:0> require "toml"
=> true
irb(main):006:0> hash = { "credentials" => [ {"host" => "127.0.0.1"} ] }
=> {"credentials"=>[{"host"=>"127.0.0.1"}]}
irb(main):007:0> TOML::Generator.new(hash).body
NoMethodError: undefined method `to_toml' for {"host"=>"127.0.0.1"}:Hash
        from /opt/boxen/rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/toml-0.1.1/lib/toml/monkey_patch.rb:19:in `block in to_toml'
        from /opt/boxen/rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/toml-0.1.1/lib/toml/monkey_patch.rb:19:in `map'
        from /opt/boxen/rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/toml-0.1.1/lib/toml/monkey_patch.rb:19:in `to_toml'
        from /opt/boxen/rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/toml-0.1.1/lib/toml/generator.rb:73:in `format'
        from /opt/boxen/rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/toml-0.1.1/lib/toml/generator.rb:55:in `block in visit'
        from /opt/boxen/rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/toml-0.1.1/lib/toml/generator.rb:49:in `each'
        from /opt/boxen/rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/toml-0.1.1/lib/toml/generator.rb:49:in `visit'
        from /opt/boxen/rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/toml-0.1.1/lib/toml/generator.rb:14:in `initialize'
        from (irb):7:in `new'
        from (irb):7
        from /opt/boxen/rbenv/versions/2.1.0/bin/irb:11:in `<main>'
zeroXten commented 9 years ago

This just bit me as well. I read an application's default config file using TOML.load_file. When I then try to generate the TOML string again it blows up:

2.1.1p76 :014 >   data = TOML.load_file('influxdb.toml')

 => {"bind-address"=>"0.0.0.0", "reporting-disabled"=>false, "logging"=>    {"level"=>"info", "file"=>"/opt/influxdb/shared/log.txt"}, "admin"=>{"port"=>8083, "assets"=>"/opt/influxdb/current/admin"}, "api"=>{"port"=>8086, "read-timeout"=>"5s"}, "input_plugins"=>{"graphite"=>{"enabled"=>false}, "udp"=>{"enabled"=>false}, "udp_servers"=>[{"enabled"=>false}]}, "raft"=>{"port"=>8090, "dir"=>"/opt/influxdb/shared/data/raft"}, "storage"=>{"dir"=>"/opt/influxdb/shared/data/db", "write-buffer-size"=>10000}, "cluster"=>{"protobuf_port"=>8099, "protobuf_timeout"=>"2s", "protobuf_heartbeat"=>"200ms", "protobuf_min_backoff"=>"1s", "protobuf_max_backoff"=>"10s", "write-buffer-size"=>10000, "max-response-buffer-size"=>100, "concurrent-shard-query-limit"=>10}, "leveldb"=>{"max-open-files"=>40, "lru-cache-size"=>"200m", "max-open-shards"=>0, "point-batch-size"=>100, "write-batch-size"=>5000000}, "sharding"=>{"replication-factor"=>1, "short-term"=>{"duration"=>"7d", "split"=>1}, "long-term"=>{"duration"=>"30d", "split"=>1}}, "wal"=>{"dir"=>"/opt/influxdb/shared/data/wal", "flush-after"=>1000, "bookmark-after"=>1000, "index-after"=>1000, "requests-per-logfile"=>10000}}

2.1.1p76 :015 > TOML::Generator.new(data).body
NoMethodError: undefined method `to_toml' for {"enabled"=>false}:Hash
parkr commented 9 years ago

Great catch! Either of you have time to whip up a quick PR for this? Looks simple enough.