Class: Reactor::Support::LinkMatcher
- Inherits:
-
Object
- Object
- Reactor::Support::LinkMatcher
- Defined in:
- lib/reactor/support/link_matcher.rb
Instance Method Summary collapse
-
#initialize(url) ⇒ LinkMatcher
constructor
A new instance of LinkMatcher.
- #recognized? ⇒ Boolean
- #rewrite_url ⇒ Object
Constructor Details
#initialize(url) ⇒ LinkMatcher
Returns a new instance of LinkMatcher.
4 5 6 |
# File 'lib/reactor/support/link_matcher.rb', line 4 def initialize(url) @url = url end |
Instance Method Details
#recognized? ⇒ Boolean
8 9 10 11 12 13 14 15 16 |
# 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 false end |
#rewrite_url ⇒ Object
18 19 20 21 22 23 24 25 26 |
# 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 |