module Primer::ViewComponents

Constants

DEFAULT_CONSTANTS_FILE_NAME
DEFAULT_STATIC_PATH
DEFAULT_STATUS_FILE_NAME
STATUSES

Public Class Methods

dump_constants(path: DEFAULT_STATIC_PATH) click to toggle source

dump_constants generates the constants hash and then serializes it as json at the given path

# File lib/primer/view_components.rb, line 53
def self.dump_constants(path: DEFAULT_STATIC_PATH)
  require "json"

  constants = generate_constants

  File.open(File.join(path, DEFAULT_CONSTANTS_FILE_NAME), "w") do |f|
    f.write(JSON.pretty_generate(constants))
    f.write($INPUT_RECORD_SEPARATOR)
  end
end
dump_statuses(path: DEFAULT_STATIC_PATH) click to toggle source

dump_statuses generates the status hash and then serializes it as json at the given path

# File lib/primer/view_components.rb, line 24
def self.dump_statuses(path: DEFAULT_STATIC_PATH)
  require "json"

  statuses = generate_statuses

  File.open(File.join(path, DEFAULT_STATUS_FILE_NAME), "w") do |f|
    f.write(JSON.pretty_generate(statuses))
    f.write($INPUT_RECORD_SEPARATOR)
  end
end
generate_constants() click to toggle source

generate_constants returns a hash mapping component name to all of its constants.

# File lib/primer/view_components.rb, line 43
def self.generate_constants
  Primer::Component.descendants.sort_by(&:name).each_with_object({}) do |component, mem|
    mem[component.to_s] = component.constants(false).sort.each_with_object({}) do |constant, h|
      h[constant] = component.const_get(constant)
    end
  end
end
generate_statuses() click to toggle source

generate_statuses returns a hash mapping component name to the component's status sorted alphabetically by the component name.

# File lib/primer/view_components.rb, line 16
def self.generate_statuses
  Primer::Component.descendants.sort_by(&:name).each_with_object({}) do |component, mem|
    mem[component.to_s] = component.status.to_s
  end
end
read_constants(path: DEFAULT_STATIC_PATH) click to toggle source

read_constants returns a JSON string matching the output of generate_constants

# File lib/primer/view_components.rb, line 66
def self.read_constants(path: DEFAULT_STATIC_PATH)
  File.read(File.join(path, DEFAULT_CONSTANTS_FILE_NAME))
end
read_statuses(path: DEFAULT_STATIC_PATH) click to toggle source

read_statuses returns a JSON string matching the output of generate_statuses

# File lib/primer/view_components.rb, line 37
def self.read_statuses(path: DEFAULT_STATIC_PATH)
  File.read(File.join(path, DEFAULT_STATUS_FILE_NAME))
end