docbrown/app/lib/rails_env_constraint.rb
Michael Kohl a1eb6358db
Easier feature flag handling for Cypress (#16379)
* Add RailsEnvConstraint for routes

* Add feature flags API

* Add Cypress commands

* Add show action, update commands, add e2e test

* Update cypress/integration/seededFlows/toggleFeatureFlags.spec.js

Co-authored-by: Suzanne Aitchison <suzanne@forem.com>

* Move helper from command to test file

* Update documentation

Co-authored-by: Suzanne Aitchison <suzanne@forem.com>
2022-02-03 10:42:13 -05:00

18 lines
612 B
Ruby

# Used as routing constraint to expose routes only in certain environments.
class RailsEnvConstraint
# @param [Array<string>] allowed_envs the environments the route(s) will be
# available in.
def initialize(allowed_envs:)
@allowed_envs = allowed_envs
end
# Returns true if we're in an allowed env
#
# @note We always ignore the request argument since it's not used.
# @return [Boolean]
def matches?(_req = nil)
# NOTE: ActiveSupport::StringInquirer works with all string methods, so
# e.g. "test" == "test".inquiry works as expected.
@allowed_envs.any?(Rails.env)
end
end