Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array of table doesn't work #31

Closed
owenthereal opened this issue Mar 24, 2014 · 2 comments
Closed

Array of table doesn't work #31

owenthereal opened this issue Mar 24, 2014 · 2 comments

Comments

@owenthereal
Copy link

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
Copy link

zeroXten commented Aug 1, 2014

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
Copy link
Collaborator

parkr commented Aug 1, 2014

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

@parkr parkr closed this as completed in dc1b51f Oct 1, 2014
parkr added a commit that referenced this issue Oct 1, 2014
Support array of tables

Fixes #31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants