Class: Keela::ExclusionValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/keela/exclusion_validator.rb

Constant Summary collapse

STRATEGY_MAP =
{
  methods: Strategies::Methods,
  scopes: Strategies::Scopes,
  constants: Strategies::Constants,
  delegations: Strategies::Delegations,
  attributes: Strategies::Attributes,
  i18n_keys: Strategies::I18nKeys
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(excluded_path) ⇒ ExclusionValidator

Returns a new instance of ExclusionValidator.



19
20
21
22
# File 'lib/keela/exclusion_validator.rb', line 19

def initialize(excluded_path)
  @excluded_path = excluded_path
  @results = { valid: [], stale: [] }
end

Instance Attribute Details

#excluded_pathObject (readonly)

Returns the value of attribute excluded_path.



17
18
19
# File 'lib/keela/exclusion_validator.rb', line 17

def excluded_path
  @excluded_path
end

#resultsObject (readonly)

Returns the value of attribute results.



17
18
19
# File 'lib/keela/exclusion_validator.rb', line 17

def results
  @results
end

Instance Method Details

#validateObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/keela/exclusion_validator.rb', line 24

def validate
  unless File.exist?(excluded_path)
    puts Rainbow("Exclusion file not found: #{excluded_path}").red
    return false
  end

  all_excluded = YAML.load_file(excluded_path, symbolize_names: true) || {}

  if all_excluded.empty?
    puts Rainbow("Exclusion file is empty: #{excluded_path}").yellow
    return true
  end

  puts "Validating exclusions in #{excluded_path}...\n\n"

  # Detect format: strategy-aware or legacy flat
  if strategy_aware_format?(all_excluded)
    validate_strategy_aware(all_excluded)
  else
    validate_legacy_flat(all_excluded)
  end

  print_results
  results[:stale].empty?
end