Skip to content

refactor activation logic / defaults to simplify Manager class #37

Description

@samandmoore

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementpinnedthis is probably a thing we should deal with

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions