Class: Ace::Lint::Molecules::GroupResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/lint/molecules/group_resolver.rb

Overview

Resolves which validator group applies to files based on pattern matching Uses configuration groups with glob patterns to determine validators

Constant Summary collapse

DEFAULT_GROUPS =

Default group configuration when no groups are defined

{
  default: {
    patterns: ["**/*.rb"],
    validators: [:standardrb],
    fallback_validators: [:rubocop]
  }
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(groups = nil) ⇒ GroupResolver

Initialize with groups configuration

Parameters:

  • groups (Hash) (defaults to: nil)

    Groups configuration from ruby.yml



24
25
26
# File 'lib/ace/lint/molecules/group_resolver.rb', line 24

def initialize(groups = nil)
  @groups = normalize_groups(groups || DEFAULT_GROUPS)
end

Instance Attribute Details

#groupsObject (readonly)

Returns the value of attribute groups.



20
21
22
# File 'lib/ace/lint/molecules/group_resolver.rb', line 20

def groups
  @groups
end

Instance Method Details

#resolve(file_path) ⇒ Hash

Resolve validator group for a single file

Parameters:

  • file_path (String)

    File path to resolve

Returns:

  • (Hash)

    { group_name:, validators:, fallback_validators:, config: }



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/ace/lint/molecules/group_resolver.rb', line 31

def resolve(file_path)
  match = Atoms::PatternMatcher.best_group_match(file_path, @groups)

  if match
    group_name, config = match
    build_result(group_name, config)
  else
    # No match - use default group if available, otherwise return nil
    default = @groups[:default]
    if default
      build_result(:default, default)
    end
  end
end

#resolve_batch(file_paths) ⇒ Hash<Symbol, Hash>

Resolve validator groups for multiple files, grouping them by matched group

Parameters:

  • file_paths (Array<String>)

    File paths to resolve

Returns:

  • (Hash<Symbol, Hash>)

    Map of group_name => { files:, validators:, … }



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/ace/lint/molecules/group_resolver.rb', line 49

def resolve_batch(file_paths)
  result = Hash.new { |h, k| h[k] = {files: []} }

  file_paths.each do |file_path|
    resolution = resolve(file_path)

    if resolution
      group_name = resolution[:group_name]
      result[group_name][:files] << file_path
      # Store group config (only once per group)
      result[group_name].merge!(resolution) { |_k, old, _new| old }
    else
      # Unmatched files go to :_unmatched_ group
      result[:_unmatched_][:files] << file_path
      result[:_unmatched_][:validators] ||= []
      result[:_unmatched_][:group_name] ||= :_unmatched_
    end
  end

  result
end