class Primer::ViewComponents::Constants
A module for constants that are used in the view components.
Constants
- CONSTANTS
Public Class Methods
get(component:, constant:, invert: true, symbolize: false)
click to toggle source
# File lib/primer/view_components/constants.rb, line 16 def get(component:, constant:, invert: true, symbolize: false) values = CONSTANTS.dig(component, constant) case values when Hash format_hash(values, invert, symbolize) when Array format_array(values, symbolize) else values end end
Private Class Methods
format_array(values, symbolize)
click to toggle source
# File lib/primer/view_components/constants.rb, line 41 def format_array(values, symbolize) val = values.select(&:present?) return val.map { |v| symbolize_value(v) } if symbolize val end
format_hash(values, invert, symbolize)
click to toggle source
# File lib/primer/view_components/constants.rb, line 31 def format_hash(values, invert, symbolize) val = invert ? values.invert : values # remove defaults val = val.except("", nil) return val.transform_values { |v| symbolize_value(v) } if symbolize val end
symbolize_value(value)
click to toggle source
# File lib/primer/view_components/constants.rb, line 49 def symbolize_value(value) ":#{value}" end