markbates / markbates/configatron
Suggestion: Unset keys should be falsy
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 593
- Forks
- 74
- PR merge metrics
- No merged PRs in 30d
Description
I love configatron, but although it solves a lot of things, it makes it rather difficult to work with unassigned keys.
In a standard hash, or an `OpenStruct`, non existing values are falsy:
```ruby
o = OpenStruct.new({ one: '1', two: '2' })
p o.three
# => nil
```
While in configatron they are truthy:
```ruby
# configatron.allow = false # unset
p configatron.allow ? "allowed" : "not allowed"
# => "allowed" (but expected "not allowed")
```
Even if I want to set defaults, I cannot work with the common ruby syntax:
```ruby
configatron.allow ||= false
```
And instead, I can only do:
```ruby
configatron.allow = false unless configatron.has_key? :allow
```
And in cases where I can't (or prefer to avoid) having defaults, in order to allow "open schema", the only way for me to handle unset keys in the same way as falsy keys, is:
```ruby
allowed = configatron.has_key?(:allow) ? configatron.allow : false
p allowed ? "allowed" : "not allowed"
```
Am I missing some functionality in configatron that will make this easier?
If there is no way to alleviate the above issues, I would love to see a change that allows it - even if it will require me to opt-in to this behavior using some config directive (in case it is desired to avoid introducing a breaking change).
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No file, test, or entry point is named. Start by tracing how configatron handles reads of unset keys, then compare that behavior with the issue's OpenStruct and ||= examples; done means unset keys behave as falsy without breaking existing configured values, with any opt-in requirement resolved.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100