class ClassVariants::Instance

Experimental RBS support (using type sampling data from the type_fusion project).

# sig/class_variants/instance.rbs

class ClassVariants::Instance
  def expand_boolean_variants: (Hash variants) -> nil
  def render: (**Hash overrides) -> String
end

def expand_boolean_variants(variants)

Experimental RBS support (using type sampling data from the type_fusion project).

def expand_boolean_variants: ( variants) -> nil

This signature was generated using 1 sample from 1 application.

def expand_boolean_variants(variants)
  variants.each.map { |key, value|
    case value
    when String
      s_key = key.to_s
      { s_key.delete_prefix("!").to_sym => { !s_key.start_with?("!") => value } }
    else
      { key => value }
    end
  }.reduce do |variants, more_variants|
    variants.merge!(more_variants) { |_key, v1, v2| v1.merge!(v2) }
  end
end

def initialize(classes = "", variants: {}, defaults: {})

def initialize(classes = "", variants: {}, defaults: {})
  @classes = classes
  @variants = expand_boolean_variants(variants)
  @defaults = defaults
end

def render(**overrides)

Experimental RBS support (using type sampling data from the type_fusion project).

def render: (**( | color | Symbol) overrides) -> String

This signature was generated using 18 samples from 1 application.

def render(**overrides)
  # Start with our default classes
  result = [@classes]
  # Then merge the passed in overrides on top of the defaults
  @defaults.merge(overrides)
    .each do |variant_type, variant|
      # dig the classes out and add them to the result
      result << @variants.dig(variant_type, variant)
    end
  # Compact out any nil values we may have dug up
  result.compact!
  # Return the final token list
  result.join " "
end