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

refactor activation logic / defaults to simplify Manager class #37

Open
samandmoore opened this issue Nov 4, 2019 · 2 comments
Open
Labels
enhancement pinned this is probably a thing we should deal with

Comments

@samandmoore
Copy link
Member

based on this suggestion here from @smudge #34 (comment)

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
@stale
Copy link

stale bot commented Dec 4, 2019

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.

@stale stale bot added the stale label Dec 4, 2019
@stale
Copy link

stale bot commented Dec 11, 2019

This issue has been automatically closed because it has not had recent activity. Thank you for your contributions.

@stale stale bot closed this as completed Dec 11, 2019
@samandmoore samandmoore reopened this Dec 11, 2019
@stale stale bot removed the stale label Dec 11, 2019
@samandmoore samandmoore added enhancement pinned this is probably a thing we should deal with labels Dec 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement pinned this is probably a thing we should deal with
Projects
None yet
Development

No branches or pull requests

1 participant