Class: HighVoltage::Constraints::RootRoute

Inherits:
Object
  • Object
show all
Defined in:
lib/high_voltage/constraints/root_route.rb

Overview

Routing constraint to validate request.path has a corresponding view

Instance Method Summary collapse

Constructor Details

#initializeRootRoute

Returns a new instance of RootRoute.



5
6
7
8
9
# File 'lib/high_voltage/constraints/root_route.rb', line 5

def initialize
  @lookup_context = ActionView::LookupContext.new(
    Rails.configuration.paths["app/views"],
  )
end

Instance Method Details

#matches?(request) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
15
# File 'lib/high_voltage/constraints/root_route.rb', line 11

def matches?(request)
  page_id = clean_page_path(request.path)
  template = File.join(content_path, page_id)
  lookup_context.exists? template
end