Module: Primer::ViewComponents
- Defined in:
- lib/primer/view_components.rb,
lib/primer/view_components/engine.rb,
lib/primer/view_components/version.rb
Overview
:nodoc:
Defined Under Namespace
Modules: VERSION Classes: Engine
Constant Summary collapse
- DEFAULT_STATUSES_PATH =
File.("static")
- DEFAULT_STATUS_FILE_NAME =
"statuses.json"
Class Method Summary collapse
-
.dump_statuses(path: DEFAULT_STATUSES_PATH) ⇒ Object
dump_statuses generates the status hash and then serializes it as json at the given path.
-
.generate_statuses ⇒ Object
generate_statuses returns a hash mapping component name to the component’s status sorted alphabetically by the component name.
-
.read_statuses(path: DEFAULT_STATUSES_PATH) ⇒ Object
read_statuses returns a JSON string matching the output of generate_statuses.
Class Method Details
.dump_statuses(path: DEFAULT_STATUSES_PATH) ⇒ Object
dump_statuses generates the status hash and then serializes it as json at the given path
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/primer/view_components.rb', line 24 def self.dump_statuses(path: DEFAULT_STATUSES_PATH) require "json" statuses = generate_statuses File.open(File.join(path, DEFAULT_STATUS_FILE_NAME), "w") do |f| f.write(statuses.to_json) f.write($INPUT_RECORD_SEPARATOR) end end |
.generate_statuses ⇒ Object
generate_statuses returns a hash mapping component name to the component’s status sorted alphabetically by the component name.
14 15 16 17 18 19 20 |
# File 'lib/primer/view_components.rb', line 14 def self.generate_statuses statuses = Primer::Component.descendants.each_with_object({}) do |component, mem| mem[component.to_s] = component.status.to_s end statuses.sort_by { |k, _v| k }.to_h end |
.read_statuses(path: DEFAULT_STATUSES_PATH) ⇒ Object
read_statuses returns a JSON string matching the output of generate_statuses
37 38 39 |
# File 'lib/primer/view_components.rb', line 37 def self.read_statuses(path: DEFAULT_STATUSES_PATH) File.read(File.join(path, DEFAULT_STATUS_FILE_NAME)) end |