Class: WCC::Contentful::Model::Redirect

Inherits:
WCC::Contentful::Model
  • Object
show all
Defined in:
lib/wcc/contentful/model/redirect.rb

Direct Known Subclasses

Redirect

Instance Method Summary collapse

Instance Method Details

#external?Boolean

A menu link is external if ‘external_link` is present and not relative.

Returns:

  • (Boolean)


9
10
11
# File 'lib/wcc/contentful/model/redirect.rb', line 9

def external?
  external_uri&.scheme.present?
end

#external_uriObject



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

#fragmentObject



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

#hrefObject

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