class Reactor::Support::LinkMatcher

Public Class Methods

new(url) click to toggle source
# File lib/reactor/support/link_matcher.rb, line 4
def initialize(url)
  @url = url
end

Public Instance Methods

recognized?() click to toggle source
# File lib/reactor/support/link_matcher.rb, line 8
def recognized?
  match = match_url
  (match[:action] == "index") &&
    (match[:controller] == "rails_connector/cms_dispatch") &&
    ((match[:id].present? && RailsConnector::AbstractObj.exists?(match[:id].to_i)) ||
    (match[:permalink].present? && RailsConnector::AbstractObj.exists?(:permalink => match[:permalink])))
rescue ActionController::RoutingError
  return false
end
rewrite_url() click to toggle source
# File lib/reactor/support/link_matcher.rb, line 18
def rewrite_url
  match = match_url

  if match[:permalink].present?
    append_fragment_and_query RailsConnector::AbstractObj.find_by_permalink(match[:permalink]).path 
  elsif match[:id].present?
    append_fragment_and_query RailsConnector::AbstractObj.find(match[:id].to_i).path
  end
end

Private Instance Methods

append_fragment_and_query(obj_path) click to toggle source
# File lib/reactor/support/link_matcher.rb, line 37
def append_fragment_and_query(obj_path)
  uri = URI.parse(@url)
  obj_path += "?#{uri.query}" if uri.query
  obj_path += "##{uri.fragment}" if uri.fragment
  obj_path
end
match_url() click to toggle source
# File lib/reactor/support/link_matcher.rb, line 29
def match_url
  return {} if @url.match(/\A[a-z0-9]*:/) # ignore fully qualified urls
  relative_url_root = ENV['RAILS_RELATIVE_URL_ROOT']
  url = @url.clone
  url.gsub!(/^#{Regexp.escape(relative_url_root)}/, '') if relative_url_root.present?
  Rails.application.routes.recognize_path(url)
end