Module: Ast::Merge::OwnerSelection

Defined in:
lib/ast/merge/owner_selection.rb

Overview

Shared helpers for recurring owner-selection and owner-matching shapes.

Class Method Summary collapse

Class Method Details

.match_by_path(template, destination, owners_key: :owners) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/ast/merge/owner_selection.rb', line 9

def match_by_path(template, destination, owners_key: :owners)
  template_owners = owners_from(template, owners_key)
  destination_owners = owners_from(destination, owners_key)
  destination_paths = owner_paths(destination_owners)
  template_paths = owner_paths(template_owners)

  {
    matched: template_owners.filter_map do |owner|
      path = owner_path(owner)
      next unless destination_paths.key?(path)

      { template_path: path, destination_path: path }
    end,
    unmatched_template: template_paths.keys.reject { |path| destination_paths.key?(path) },
    unmatched_destination: destination_paths.keys.reject { |path| template_paths.include?(path) }
  }
end

.owner_path(owner) ⇒ Object



38
39
40
# File 'lib/ast/merge/owner_selection.rb', line 38

def owner_path(owner)
  value_for(owner, :path)
end

.owner_paths(owners) ⇒ Object



46
47
48
# File 'lib/ast/merge/owner_selection.rb', line 46

def owner_paths(owners)
  Array(owners).to_h { |owner| [owner_path(owner), true] }
end

.owners_from(analysis, owners_key) ⇒ Object



42
43
44
# File 'lib/ast/merge/owner_selection.rb', line 42

def owners_from(analysis, owners_key)
  value_for(analysis, owners_key) || []
end

.selector_kind(owner_selector, logical_owners: {}) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/ast/merge/owner_selection.rb', line 27

def selector_kind(owner_selector, logical_owners: {})
  normalized = owner_selector&.to_sym
  if logical_owners && !logical_owners.empty?
    :logical_owner
  elsif normalized == :shared_default
    :shared_default
  else
    :explicit
  end
end