Class: Cadmus::SlugConstraint
- Inherits:
-
Object
- Object
- Cadmus::SlugConstraint
- Defined in:
- lib/cadmus/routing.rb
Overview
A routing constraint that determines whether a request has a valid Cadmus page glob. A page glob consists of one or more valid slug parts separated by forward slashes. A valid slug part consists of a lower-case letter followed by any combination of lower-case letters, digits, and hyphens.
Instance Method Summary collapse
-
#matches?(request) ⇒ Boolean
True if this request’s +:page_glob+ parameter is a valid Cadmus page glob, false if it’s not.
Instance Method Details
#matches?(request) ⇒ Boolean
Returns true if this request’s +:page_glob+ parameter is a valid Cadmus page glob, false if it’s not. Allows +:page_glob+ to be nil only if the Rails environment is +test+, because +assert_recognizes+ doesn’t always pass the full params hash including globbed parameters.
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/cadmus/routing.rb', line 12 def matches?(request) page_glob = request.path_parameters.symbolize_keys[:page_glob] # assert_recognizes doesn't pass the full params hash as we would in a real Rails # application. So we have to always pass this constraint if we're testing. return true if page_glob.nil? && Rails.env.test? page_glob.sub(/\A\//, '').split(/\//).all? do |part| part =~ /\A[a-z][a-z0-9\-]*\z/ end end |