Automatic predicate methods for coerced booleans
jhirn opened this issue · 4 comments
Given a config with a coerced boolean, it would be really nice to have predicate methods generated automatically. I'm thinking this is something that you might want to disable rather than opt-in to, but I'd be fine with either way.
class MyConfig < Anyway::Config
attr_config enabled: "true"
coerce_boolean enabled: :boolean
end
MyConfig.new.enabled? #=> true
# config
config.anyway_config.predicates_for_coerced_booleans = [false | true]
If it's wanted. I can try to put up a PR for this.
Hey!
We already create predicate methods when the default value is true
or false
(so, in you case enabled: true
will ad the #enabled?
) method:
anyway_config/lib/anyway/config.rb
Lines 105 to 108 in 83d79cc
Anyway, I think, taking defined corrections into account also makes sense, so I'm open for a PR
Oh nice. Yeah I'm assuming that may not work for ENVs?
coerce_types
is the final say in the type so adding it there would be a nice addition. As soon as I'm done converting this 6yr old legacy app to AnywayConfig I'll take a stab at a PR.
Thank you!