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

config_context_list and config_context_hash only work with .rb config files #58

Open
elyscape opened this issue May 21, 2018 · 0 comments

Comments

@elyscape
Copy link
Contributor

Context lists and context hashes only work with Ruby config files. Attempting to use a JSON, YAML, or TOML file or load from a hash results in an error:

irb(main):001:0> require 'mixlib/config'
=> true
irb(main):002:0> class Config
irb(main):003:1>   extend Mixlib::Config
irb(main):004:1>   config_context_list :tests, :test do
irb(main):005:2*     default :x, 5
irb(main):006:2>   end
irb(main):007:1> end
=> [#<Proc:0x00007ffb3b068d88@(irb):4>]
irb(main):008:0> puts File.read('conf.yaml')
---
tests:
  - x: 7
  - x: 14
=> nil
irb(main):009:0> Config.from_file 'conf.yaml'
ArgumentError: wrong number of arguments (given 1, expected 0)
[elided]
irb(main):010:0> Config.from_hash({ tests: [{x:7}, {x:14}] })
ArgumentError: wrong number of arguments (given 1, expected 0)
[elided]

The issue is in the from_hash method. It attempts to convert a hash into executable Ruby code and then executes it. Unfortunately, this doesn't work for context lists and hashes. Here's what it produces from the sample config above:

tests [{"x"=>7}, {"x"=>14}]

This seems like it might work but, unfortunately, config_context_list and config_context_hash do not create methods for the plural symbol that take arguments.

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

1 participant