Sha256: b9410a9bff58b7cad732ad8647d1ac62fd0c76c0a3fb96288cdd9c43bc2e46d0

Contents?: true

Size: 1.91 KB

Versions: 60

Compression:

Stored size: 1.91 KB

Contents

# frozen_string_literal: true

require "primer/classify"
require "primer/view_components/version"
require "primer/view_components/engine"

module Primer
  # :nodoc:
  module ViewComponents
    DEFAULT_STATIC_PATH = File.expand_path("static")
    FILE_NAMES = {
      statuses: "statuses.json",
      constants: "constants.json",
      audited_at: "audited_at.json"
    }.freeze

    # generate_statuses returns a hash mapping component name to
    # the component's status sorted alphabetically by the component name.
    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

    # generate_audited_at returns a hash mapping component name to
    # the day the component has passed an accessibility audit.
    def self.generate_audited_at
      Primer::Component.descendants.sort_by(&:name).each_with_object({}) do |component, mem|
        mem[component.to_s] = component.audited_at.to_s
      end
    end

    # generate_constants returns a hash mapping component name to
    # all of its constants.
    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

    # dump generates the requested stat hash and outputs it to a file.
    def self.dump(stats)
      require "json"

      File.open(File.join(DEFAULT_STATIC_PATH, FILE_NAMES[stats]), "w") do |f|
        f.write(JSON.pretty_generate(send("generate_#{stats}")))
        f.write($INPUT_RECORD_SEPARATOR)
      end
    end

    # read returns a JSON string matching the output of the corresponding stat.
    def self.read(stats)
      File.read(File.join(DEFAULT_STATIC_PATH, FILE_NAMES[stats]))
    end
  end
end

Version data entries

60 entries across 60 versions & 1 rubygems

Version Path
primer_view_components-0.0.119 lib/primer/view_components.rb
primer_view_components-0.0.118 lib/primer/view_components.rb
primer_view_components-0.0.117 lib/primer/view_components.rb
primer_view_components-0.0.116 lib/primer/view_components.rb
primer_view_components-0.0.115 lib/primer/view_components.rb
primer_view_components-0.0.114 lib/primer/view_components.rb
primer_view_components-0.0.113 lib/primer/view_components.rb
primer_view_components-0.0.112 lib/primer/view_components.rb
primer_view_components-0.0.111 lib/primer/view_components.rb
primer_view_components-0.0.110 lib/primer/view_components.rb
primer_view_components-0.0.109 lib/primer/view_components.rb
primer_view_components-0.0.108 lib/primer/view_components.rb
primer_view_components-0.0.107 lib/primer/view_components.rb
primer_view_components-0.0.106 lib/primer/view_components.rb
primer_view_components-0.0.105 lib/primer/view_components.rb
primer_view_components-0.0.104 lib/primer/view_components.rb
primer_view_components-0.0.103 lib/primer/view_components.rb
primer_view_components-0.0.102 lib/primer/view_components.rb
primer_view_components-0.0.101 lib/primer/view_components.rb
primer_view_components-0.0.100 lib/primer/view_components.rb