Created
June 29, 2025 07:15
-
-
Save rgarner/74f17bd661c9f82b024c65076e76abae to your computer and use it in GitHub Desktop.
Enabling feature plugins via constraint
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Rails.application.routes.draw do | |
# to enable feature1, `touch tmp/feature1` | |
class FeatureEnabledConstraint | |
def matches?(request) | |
match = request.path.match %r{/plugins/(?<feature_name>[^/]*)} | |
Rails.logger.info "MATCHED #{request.path} with #{match.inspect}" | |
File.exist?("tmp/#{match[:feature_name]}") | |
end | |
end | |
class Feature1 | |
def self.call(env) = return [200, {}, ['feature 1']] | |
end | |
class Feature2 | |
def self.call(env) = return [200, {}, ['feature 2']] | |
end | |
class Feature3 | |
def self.call(env) = return [200, {}, ['feature 3']] | |
end | |
constraints(FeatureEnabledConstraint.new) { mount Feature1, at: '/plugins/feature1' } | |
constraints(FeatureEnabledConstraint.new) { mount Feature2, at: '/plugins/feature2' } | |
constraints(FeatureEnabledConstraint.new) { mount Feature3, at: '/plugins/feature3' } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment