Sha256: 9afdfb607cb9076ec2d80be0ba206bd00fe4c30d48486ed8a0386eb4786f29a6
Contents?: true
Size: 1.25 KB
Versions: 24
Compression:
Stored size: 1.25 KB
Contents
# frozen_string_literal: true # Ariadne::FetchOrFallbackHelper # A little helper to enable graceful fallbacks # # Use this helper to quietly ensure a value is # one that you expect: # # allowed_values - allowed options for *value* # given_value - input being coerced # fallback - returned if *given_value* is not included in *allowed_values* # # fetch_or_raise([1,2,3], 5) => 2 # fetch_or_raise([1,2,3], 1) => 1 # fetch_or_raise([1,2,3], nil) => 2 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) fetch_or_raise(HeroiconsHelper::Icon::VALID_VARIANTS, variant) true end 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
24 entries across 24 versions & 1 rubygems