Reputation: 110950
I have a list of url paths:
WHITELIST_PATHS = [ '/assets', '/images', '/javascripts']
How can regex be used to do something like:
allow_access = WHITELIST_PATHS.include? '/assets/application.css'
Idea being that the tested path just needs to start with a whitelist path. Ideas? Thanks
Upvotes: 0
Views: 278
Reputation: 10907
WHITELIST_PATHS = [ '/assets', '/images', '/javascripts']
# probably should be
# WHITELIST_PATHS = [ '/assets/', '/images/', '/javascripts/']
WHITELIST_REGEXP = /^(#{WHITELIST_PATHS.join("|")})/
allow_access = !!('/assets/application.css' =~ WHITELIST_REGEXP)
Upvotes: 1
Reputation: 118671
allow_access = WHITELIST_PATHS.any? {|p| '/assets/application.css'.start_with? p }
Upvotes: 3