Sha256: fe693f4ebcf0c727196684ac25261afee44cb0b0c3d431f3c69d5f92ab7393c9

Contents?: true

Size: 762 Bytes

Versions: 32

Compression:

Stored size: 762 Bytes

Contents

# frozen_string_literal: true

class WCC::Contentful::Model::Redirect < WCC::Contentful::Model
  def external_uri
    @external_uri ||= URI(external_link) if external_link.present?
  end

  # A menu link is external if `external_link` is present and not relative.
  def external?
    external_uri&.scheme.present?
  end

  # Gets either the external link or the slug from the referenced page.
  # Example usage: `redirect_to redirect.href`
  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

  def fragment
    WCC::Contentful::App::SectionHelper.section_id(section_link) if section_link
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
wcc-contentful-app-1.7.1 lib/wcc/contentful/model/redirect.rb
wcc-contentful-app-1.7.0 lib/wcc/contentful/model/redirect.rb
wcc-contentful-app-1.6.2 lib/wcc/contentful/model/redirect.rb
wcc-contentful-app-1.6.1 lib/wcc/contentful/model/redirect.rb
wcc-contentful-app-1.6.0 lib/wcc/contentful/model/redirect.rb
wcc-contentful-app-1.5.1 lib/wcc/contentful/model/redirect.rb
wcc-contentful-app-1.5.0 lib/wcc/contentful/model/redirect.rb
wcc-contentful-app-1.5.0.rc1 lib/wcc/contentful/model/redirect.rb
wcc-contentful-app-1.4.0 lib/wcc/contentful/model/redirect.rb
wcc-contentful-app-1.4.0.rc3 lib/wcc/contentful/model/redirect.rb
wcc-contentful-app-1.4.0.rc2 lib/wcc/contentful/model/redirect.rb
wcc-contentful-app-1.3.2 lib/wcc/contentful/model/redirect.rb
wcc-contentful-app-1.4.0.rc1 lib/wcc/contentful/model/redirect.rb
wcc-contentful-app-1.3.1 lib/wcc/contentful/model/redirect.rb
wcc-contentful-app-1.3.0 lib/wcc/contentful/model/redirect.rb
wcc-contentful-app-1.2.1 lib/wcc/contentful/model/redirect.rb
wcc-contentful-app-1.2.0 lib/wcc/contentful/model/redirect.rb
wcc-contentful-app-1.1.2 lib/wcc/contentful/model/redirect.rb
wcc-contentful-app-1.1.1 lib/wcc/contentful/model/redirect.rb
wcc-contentful-app-1.1.0 lib/wcc/contentful/model/redirect.rb