Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 25 lines (19 sloc) 0.554 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
module HighVoltage
  module Constraints
    # Routing constraint to validate request.path has a corresponding view
    class RootRoute
      VIEW_EXTENSIONS = 'html.erb,html.haml,html'

      def self.matches?(request)
        pattern = file_pattern(request.path)

        Dir.glob(pattern).any?
      end

      private

      def self.file_pattern(page_id)
        "#{content_path}#{page_id}.{#{VIEW_EXTENSIONS}}"
      end

      def self.content_path
        Rails.root.join('app', 'views', HighVoltage.content_path).to_s
      end
    end
  end
end
Something went wrong with that request. Please try again.