Class: Administrate::Field::Hyperlink

Inherits:
String
  • Object
show all
Includes:
HyperlinkVersion
Defined in:
lib/administrate/field/hyperlink.rb

Defined Under Namespace

Classes: Engine

Constant Summary

Constants included from HyperlinkVersion

Administrate::Field::HyperlinkVersion::VERSION

Instance Method Summary collapse

Instance Method Details

#hrefObject



22
23
24
25
26
27
# File 'lib/administrate/field/hyperlink.rb', line 22

def href
  return options.fetch(:fallback_href) { nil } unless data.present?
  return data if data.include?('://') || data.start_with?('//')

  "#{options.fetch(:scheme) { 'https://' }}#{data}"
end

#present?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/administrate/field/hyperlink.rb', line 12

def present?
  (data.presence || options.fetch(:fallback_href) { nil }).present?
end

#to_sObject



16
17
18
19
20
# File 'lib/administrate/field/hyperlink.rb', line 16

def to_s
  options.fetch(:label) do
    data.presence || options.fetch(:fallback_href) { nil }
  end
end