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/commands.rb,
lib/ariadne/view_components/statuses.rb,
lib/ariadne/view_components/upstream.rb,
lib/ariadne/view_components/constants.rb

Overview

:nodoc:

Defined Under Namespace

Modules: Commands, Upstream Classes: Constants, Engine

Constant Summary collapse

DEFAULT_STATIC_PATH =
File.expand_path("static")
FILE_NAMES =
{
  statuses: "statuses.json",
  constants: "constants.json",
  audited_at: "audited_at.json",
}.freeze
VERSION =
"0.0.93.1"
STATUSES =
JSON.parse(
  File.read(
    File.join(File.dirname(__FILE__), "../../../static/statuses.json"),
  ),
).freeze

Class Method Summary collapse

Class Method Details

.dump(stats) ⇒ Object

dump generates the requested stat hash and outputs it to a file.



46
47
48
49
50
51
52
53
# File 'lib/ariadne/view_components.rb', line 46

def 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_atObject

generate_audited_at returns a hash mapping component name to the day the component has passed an accessibility audit.



29
30
31
32
33
# File 'lib/ariadne/view_components.rb', line 29

def 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_constantsObject

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



37
38
39
40
41
42
43
# File 'lib/ariadne/view_components.rb', line 37

def generate_constants
  Ariadne::Component.descendants.sort_by(&:name).each_with_object({}) do |component, mem|
    mem[component.to_s] = component.constants(false).sort.index_with do |constant|
      component.const_get(constant)
    end
  end
end

.generate_statusesObject

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



21
22
23
24
25
# File 'lib/ariadne/view_components.rb', line 21

def 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.



56
57
58
# File 'lib/ariadne/view_components.rb', line 56

def read(stats)
  File.read(File.join(DEFAULT_STATIC_PATH, FILE_NAMES[stats]))
end