Class: Tenon::Redirector

Inherits:
Object
  • Object
show all
Defined in:
app/services/tenon/redirector.rb

Instance Method Summary collapse

Constructor Details

#initialize(path, redirects = Tenon::Redirect.active) ⇒ Redirector

Returns a new instance of Redirector.



12
13
14
15
# File 'app/services/tenon/redirector.rb', line 12

def initialize(path, redirects = Tenon::Redirect.active)
  @path = path
  @redirects = redirects
end

Instance Method Details

#redirectObject



17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/services/tenon/redirector.rb', line 17

def redirect
  # If 404 -> Compare the path to all Redirect records:
  @destination = get_destination
  # raise @destination.inspect
  if @destination.present?
    # If there is a match return destination:
    return @destination
  else
    # Else -> trigger the 404 again:
    raise ActiveRecord::RecordNotFound
  end
end