Sha256: da24f1e728c86df639d1a93bd166493d52555d3a2374d3e25f5f11d1bb8897f4
Contents?: true
Size: 1.24 KB
Versions: 6
Compression:
Stored size: 1.24 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::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
6 entries across 6 versions & 1 rubygems