refactor activation logic / defaults to simplify Manager class
based on this suggestion here from @smudge https://github.com/Betterment/webvalve/pull/34#discussion_r341619281
I wonder if in some earlier routine it would make sense to do something like this:
def set_defaults!
if Webvalve.env.in?(ALWAYS_ENABLED_ENVS)
if ENV.key? 'WEBVALVE_SERVICE_ENABLED_DEFAULT'
WebValve.logger.warn SERVICE_ENABLED_DEFAULT_WARNING
end
if ENV.key? 'WEBVALVE_ENABLED'
WebValve.logger.warn WEBVALVE_ENABLED_WARNING
end
ENV['WEBVALVE_ENABLED'] = '1'
ENV['WEBVALVE_SERVICE_ENABLED_DEFAULT'] = '0'
else
ENV['WEBVALVE_ENABLED'] ||= '0'
ENV['WEBVALVE_SERVICE_ENABLED_DEFAULT'] ||= '1'
end
end
And then inside of Manager there doesn't need to be a concept of "always" or "explicit" - it can more naively trust that the two ENV vars are set and mean what they say they mean:
def enabled?
ENABLED_VALUES.include?(ENV.fetch('WEBVALVE_ENABLED'))
end
def services_enabled_by_default?
ENABLED_VALUES.include?(ENV.fetch('WEBVALVE_SERVICE_ENABLED_DEFAULT'))
end
def allowing?
enabled? && services_enabled_by_default?
end
def intercepting?
enabled? && !services_enabled_by_default?
end
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been automatically closed because it has not had recent activity. Thank you for your contributions.