Sha256: 2bf65a5347173aca9a0750483d943d11f6d59433c1bf69290e1d5855b449cc0e
Contents?: true
Size: 1.25 KB
Versions: 313
Compression:
Stored size: 1.25 KB
Contents
# frozen_string_literal: true # Ariadne::IconHelper # A helper that insists on certain values when # checking herocions and their varients. # # Use this helper to loudly ensure a value is # one that you expect. module Ariadne # :nodoc: module IconHelper include FetchOrFallbackHelper 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 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 module_function :ensure_valid_variant def has_partial_icon?(icon, variant) icon.present? || variant.present? end def icon_presence!(icon, variant) raise(ArgumentError, "You must provide an `icon` when providing a `variant`.") if icon.blank? && variant.present? true end def variant_presence!(icon, variant) raise(ArgumentError, "You must provide a `variant` when providing an `icon`.") if icon.present? && variant.blank? true end end end
Version data entries
313 entries across 313 versions & 1 rubygems