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

Version Path
ariadne_view_components-0.0.93.2 app/lib/ariadne/icon_helper.rb
ariadne_view_components-0.0.93.1 app/lib/ariadne/icon_helper.rb
ariadne_view_components-0.0.93 app/lib/ariadne/icon_helper.rb
ariadne_view_components-0.0.92 app/lib/ariadne/icon_helper.rb
ariadne_view_components-0.0.91 app/lib/ariadne/icon_helper.rb
ariadne_view_components-0.0.90 app/lib/ariadne/icon_helper.rb
ariadne_view_components-0.0.89.1 app/lib/ariadne/icon_helper.rb
ariadne_view_components-0.0.89 app/lib/ariadne/icon_helper.rb
ariadne_view_components-0.0.88 app/lib/ariadne/icon_helper.rb
ariadne_view_components-0.0.87 app/lib/ariadne/icon_helper.rb
ariadne_view_components-0.0.86.9 app/lib/ariadne/icon_helper.rb
ariadne_view_components-0.0.86.8 app/lib/ariadne/icon_helper.rb
ariadne_view_components-0.0.86.7 app/lib/ariadne/icon_helper.rb
ariadne_view_components-0.0.86.6 app/lib/ariadne/icon_helper.rb
ariadne_view_components-0.0.86.5 app/lib/ariadne/icon_helper.rb
ariadne_view_components-0.0.86.4 app/lib/ariadne/icon_helper.rb
ariadne_view_components-0.0.86.3 app/lib/ariadne/icon_helper.rb
ariadne_view_components-0.0.86.2 app/lib/ariadne/icon_helper.rb
ariadne_view_components-0.0.86.1 app/lib/ariadne/icon_helper.rb
ariadne_view_components-0.0.86 app/lib/ariadne/icon_helper.rb