Class: WCC::Contentful::Model::Redirect
- Inherits:
-
WCC::Contentful::Model
- Object
- WCC::Contentful::Model
- WCC::Contentful::Model::Redirect
- Defined in:
- lib/wcc/contentful/model/redirect.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#external? ⇒ Boolean
A menu link is external if ‘external_link` is present and not relative.
- #external_uri ⇒ Object
- #fragment ⇒ Object
-
#href ⇒ Object
Gets either the external link or the slug from the referenced page.
Instance Method Details
#external? ⇒ Boolean
A menu link is external if ‘external_link` is present and not relative.
9 10 11 |
# File 'lib/wcc/contentful/model/redirect.rb', line 9 def external? external_uri&.scheme.present? end |
#external_uri ⇒ Object
4 5 6 |
# File 'lib/wcc/contentful/model/redirect.rb', line 4 def external_uri @external_uri ||= URI(external_link) if external_link.present? end |
#fragment ⇒ Object
26 27 28 |
# File 'lib/wcc/contentful/model/redirect.rb', line 26 def fragment WCC::Contentful::App::SectionHelper.section_id(section_link) if section_link end |
#href ⇒ Object
Gets either the external link or the slug from the referenced page. Example usage: ‘redirect_to redirect.href`
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/wcc/contentful/model/redirect.rb', line 15 def href return external_link if external_link url = (link&.try(:slug) || link&.try(:url)) return url unless fragment.present? url = URI(url || '') url.fragment = fragment url.to_s end |