Sha256: 7448ae624114caa9151d9c88527572bc77dc2773d0d441d42a4ea157f2056c75

Contents?: true

Size: 1.1 KB

Versions: 87

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

module Alchemy
  # Routing constraints for Alchemy's strong catch all route.
  #
  # Alchemy has a very strong catch all route.
  # But we don't want to handle all requests.
  #
  # For instance we only want to handle html and rss requests and
  # don't want to swallow the rails/info routes in development mode.
  #
  class RoutingConstraints
    LOCALE_REGEXP = /[a-z]{2}(-[a-zA-Z]{2})?/

    def matches?(request)
      @request = request
      @params = @request.params

      handable_format? && no_rails_route?
    end

    private

    # We only want html and rss requests to be handled by us.
    #
    # If an unknown format is requested we want to handle this,
    # because it could be a legacy route that needs to be redirected.
    #
    def handable_format?
      @request.format.symbol.nil? || (@request.format.symbol == :html) || (@request.format.symbol == :rss)
    end

    # We don't want to handle the Rails info routes.
    def no_rails_route?
      return true if !%w(development test).include?(Rails.env)

      (@params["urlname"] =~ /\Arails\//).nil?
    end
  end
end

Version data entries

87 entries across 87 versions & 1 rubygems

Version Path
alchemy_cms-5.3.6 lib/alchemy/routing_constraints.rb
alchemy_cms-6.0.7 lib/alchemy/routing_constraints.rb
alchemy_cms-6.0.6 lib/alchemy/routing_constraints.rb
alchemy_cms-6.0.5 lib/alchemy/routing_constraints.rb
alchemy_cms-6.0.4 lib/alchemy/routing_constraints.rb
alchemy_cms-6.0.3 lib/alchemy/routing_constraints.rb
alchemy_cms-6.0.2 lib/alchemy/routing_constraints.rb
alchemy_cms-6.0.1 lib/alchemy/routing_constraints.rb
alchemy_cms-5.3.5 lib/alchemy/routing_constraints.rb
alchemy_cms-6.0.0 lib/alchemy/routing_constraints.rb
alchemy_cms-5.3.4 lib/alchemy/routing_constraints.rb
alchemy_cms-6.0.0.pre.rc7 lib/alchemy/routing_constraints.rb
alchemy_cms-5.3.3 lib/alchemy/routing_constraints.rb
alchemy_cms-5.3.2 lib/alchemy/routing_constraints.rb
alchemy_cms-5.3.1 lib/alchemy/routing_constraints.rb
alchemy_cms-5.3.0 lib/alchemy/routing_constraints.rb
alchemy_cms-6.0.0.pre.rc6 lib/alchemy/routing_constraints.rb
alchemy_cms-5.2.7 lib/alchemy/routing_constraints.rb
alchemy_cms-5.2.6 lib/alchemy/routing_constraints.rb
alchemy_cms-5.1.10 lib/alchemy/routing_constraints.rb