Class: Ace::Lint::Molecules::GroupResolver
- Inherits:
-
Object
- Object
- Ace::Lint::Molecules::GroupResolver
- 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
-
#groups ⇒ Object
readonly
Returns the value of attribute groups.
Instance Method Summary collapse
-
#initialize(groups = nil) ⇒ GroupResolver
constructor
Initialize with groups configuration.
-
#resolve(file_path) ⇒ Hash
Resolve validator group for a single file.
-
#resolve_batch(file_paths) ⇒ Hash<Symbol, Hash>
Resolve validator groups for multiple files, grouping them by matched group.
Constructor Details
#initialize(groups = nil) ⇒ GroupResolver
Initialize with groups configuration
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
#groups ⇒ Object (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
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
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 |