Module: Ariadne::IconHelper

Includes:
FetchOrFallbackHelper
Included in:
UI::Heroicon::Component
Defined in:
app/lib/ariadne/icon_helper.rb

Overview

:nodoc:

Constant Summary

Constants included from FetchOrFallbackHelper

FetchOrFallbackHelper::INTEGER_TYPES, FetchOrFallbackHelper::InvalidValueError, FetchOrFallbackHelper::TRUE_OR_FALSE

Class Method Summary collapse

Instance Method Summary collapse

Methods included from FetchOrFallbackHelper

#check_incoming_attribute, #check_incoming_tag, #check_incoming_value, #fetch_or_fallback, #fetch_or_raise, #fetch_or_raise_boolean, #fetch_or_raise_integer

Methods included from LoggerHelper

#logger, #silence_deprecations?, #silence_warnings?

Class Method Details

.ensure_valid_variant(variant) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'app/lib/ariadne/icon_helper.rb', line 24

def ensure_valid_variant(variant)
  check_variant = if variant.blank? || !variant.respond_to?(:to_s)
    ""
  else
    variant.to_s
  end

  fetch_or_raise(HeroiconsHelper::Icon::VALID_VARIANTS, check_variant)
end

Instance Method Details

#check_icon_presence!(icon, variant) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'app/lib/ariadne/icon_helper.rb', line 14

def check_icon_presence!(icon, variant)
  return true unless has_partial_icon?(icon, variant)

  icon_presence!(icon, variant)
  variant_presence!(icon, variant)
  ensure_valid_variant(variant)

  true
end

#has_partial_icon?(icon, variant) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'app/lib/ariadne/icon_helper.rb', line 35

def has_partial_icon?(icon, variant)
  icon.present? || variant.present?
end

#icon_presence!(icon, variant) ⇒ Object

Raises:

  • (ArgumentError)


39
40
41
42
43
# File 'app/lib/ariadne/icon_helper.rb', line 39

def icon_presence!(icon, variant)
  raise(ArgumentError, "You must provide an `icon` when providing a `variant`.") if icon.blank? && variant.present?

  true
end

#variant_presence!(icon, variant) ⇒ Object

Raises:

  • (ArgumentError)


45
46
47
48
49
# File 'app/lib/ariadne/icon_helper.rb', line 45

def variant_presence!(icon, variant)
  raise(ArgumentError, "You must provide a `variant` when providing an `icon`.") if icon.present? && variant.blank?

  true
end