Module: Ariadne::ViewComponents
- Defined in:
- lib/ariadne/view_components.rb,
lib/ariadne/view_components/engine.rb,
lib/ariadne/view_components/version.rb,
lib/ariadne/view_components/statuses.rb,
lib/ariadne/view_components/constants.rb
Overview
:nodoc:
Defined Under Namespace
Constant Summary collapse
- DEFAULT_STATIC_PATH =
File.("static")
- FILE_NAMES =
{ statuses: "statuses.json", constants: "constants.json", audited_at: "audited_at.json", }.freeze
- VERSION =
"0.0.1"- STATUSES =
JSON.parse( File.read( File.join(File.dirname(__FILE__), "../../../static/statuses.json") ) ).freeze
Class Method Summary collapse
-
.dump(stats) ⇒ Object
dump generates the requested stat hash and outputs it to a file.
-
.generate_audited_at ⇒ Object
generate_audited_at returns a hash mapping component name to the day the component has passed an accessibility audit.
-
.generate_constants ⇒ Object
generate_constants returns a hash mapping component name to all of its constants.
-
.generate_statuses ⇒ Object
generate_statuses returns a hash mapping component name to the component’s status sorted alphabetically by the component name.
-
.read(stats) ⇒ Object
read returns a JSON string matching the output of the corresponding stat.
Class Method Details
.dump(stats) ⇒ Object
dump generates the requested stat hash and outputs it to a file.
45 46 47 48 49 50 51 52 |
# File 'lib/ariadne/view_components.rb', line 45 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 |
.generate_audited_at ⇒ Object
generate_audited_at returns a hash mapping component name to the day the component has passed an accessibility audit.
28 29 30 31 32 |
# File 'lib/ariadne/view_components.rb', line 28 def self.generate_audited_at Ariadne::Component.descendants.sort_by(&:name).each_with_object({}) do |component, mem| mem[component.to_s] = component.audited_at.to_s end end |
.generate_constants ⇒ Object
generate_constants returns a hash mapping component name to all of its constants.
36 37 38 39 40 41 42 |
# File 'lib/ariadne/view_components.rb', line 36 def self.generate_constants Ariadne::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 ⇒ Object
generate_statuses returns a hash mapping component name to the component’s status sorted alphabetically by the component name.
20 21 22 23 24 |
# File 'lib/ariadne/view_components.rb', line 20 def self.generate_statuses Ariadne::Component.descendants.sort_by(&:name).each_with_object({}) do |component, mem| mem[component.to_s] = component.status.to_s end end |
.read(stats) ⇒ Object
read returns a JSON string matching the output of the corresponding stat.
55 56 57 |
# File 'lib/ariadne/view_components.rb', line 55 def self.read(stats) File.read(File.join(DEFAULT_STATIC_PATH, FILE_NAMES[stats])) end |