-
Notifications
You must be signed in to change notification settings - Fork 51
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
Allow for stringified options keys #7
Conversation
When config caches come from YAML files and the like it's sometimes difficult to trace whether a specific config key is a symbol. This leads to obscure error messages. Therefore it's sane to recursively symbolize the option hash keys and do a little allowance for the delivery option flag to be a string. This makes Pony friends with YAML configs without extraneous to_sym calls.
This reverts commit 6c7105b.
For example, hashes from YAML configs are usually string keyed, however we do not want to convert everything we receive into symbols since this can pollute the symbol table and lead to memory leaks. We therefore use a proxy class which acts sort of like the HashWithIndifferentAccess proxy, and will fetch is values from the hash with string keys when requested by symbol. The downside is that we need to wrap calls to options with this decorator every time, which we do using a delegate.
Please note that due to some bug with Github you actually need to pull in this commit |
Julik, Thanks for working on this and I appreciate the spelling fixes too :). I'd prefer one of two solutions:
Thanks --Ben On Mon, Jan 9, 2012 at 3:16 AM, Julik Tarkhanov
|
Thanks for the quick reaction! I'll take a stab at using Hashie, if you don't object to it becoming a dependency. Specifying symbols in YAML is an option but the first Google result for it will likely be the Ruby yaml class notation which is ugly. |
Hm. Unfortunately IndifferentAccess is only in the 2.0 branch of Hashie which is not stable yet. Is it good for Pony to depend on a prerelease gem? Maybe you could include my stub as a temporary solution and replace it with Hashie once they push out 2.0? |
I'd like to draw attention back to this pull request. Applications using This is an example of the manual conversion I need to do in my own code now: So one way or the other, pony should stop depending on Ruby-specific YAML processing. |
This is still an issue -- libraries in Ruby-land, where configuration is frequently read in from YAML files, should accept either string or symbol keys. Ruby-specific processing of YAML files, which symbol keys depends on, is a security antipattern. |
Closing this PR, but opening issue #20 to put together a fix. |
I've reworked the patch now to not convert the hashes every time (since this could introduce memory leaks into the system when too many mailcious string keys would be sent).