Class: InertiaI18n::HealthChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/inertia_i18n/health_checker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeHealthChecker

Returns a new instance of HealthChecker.



7
8
9
10
11
12
# File 'lib/inertia_i18n/health_checker.rb', line 7

def initialize
  @config = InertiaI18n.configuration
  @locales = LocaleLoader.load_all
  @scan_results = Scanner.new.scan
  @issues = {missing: [], unused: [], unsync: []}
end

Instance Attribute Details

#issuesObject (readonly)

Returns the value of attribute issues.



5
6
7
# File 'lib/inertia_i18n/health_checker.rb', line 5

def issues
  @issues
end

#localesObject (readonly)

Returns the value of attribute locales.



5
6
7
# File 'lib/inertia_i18n/health_checker.rb', line 5

def locales
  @locales
end

#scan_resultsObject (readonly)

Returns the value of attribute scan_results.



5
6
7
# File 'lib/inertia_i18n/health_checker.rb', line 5

def scan_results
  @scan_results
end

Instance Method Details

#check!(checks: [:missing, :unused, :unsync]) ⇒ Object



14
15
16
17
18
19
# File 'lib/inertia_i18n/health_checker.rb', line 14

def check!(checks: [:missing, :unused, :unsync])
  check_missing_keys if checks.include?(:missing)
  check_unused_keys if checks.include?(:unused)
  check_locale_sync if checks.include?(:unsync)
  self
end

#healthy?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/inertia_i18n/health_checker.rb', line 21

def healthy?
  @issues.values.all?(&:empty?)
end

#summaryObject



25
26
27
28
29
30
31
32
33
34
# File 'lib/inertia_i18n/health_checker.rb', line 25

def summary
  {
    total_errors: @issues.values.flatten.count { |i| i[:severity] == :error },
    total_warnings: @issues.values.flatten.count { |i| i[:severity] == :warning },
    missing_count: @issues[:missing].size,
    unused_count: @issues[:unused].size,
    unsync_count: @issues[:unsync].size,
    healthy: healthy?
  }
end