class Owners::Search
Accepts an array of file paths and returns an array of {Owner} objects that have subscribed to the files.
@api private
Constants
- RELATIVE
Public Class Methods
new(files, configs = nil, shallow: false)
click to toggle source
# File lib/owners/search.rb 9 def initialize(files, configs = nil, shallow: false) 10 @files = files.map(&:dup) 11 @configs = configs 12 @shallow = shallow 13 end
Public Instance Methods
owners()
click to toggle source
# File lib/owners/search.rb 19 def owners 20 subscribers.map do |subscriber| 21 Owner.new(subscriber).tap do |owner| 22 subscriptions.each do |path, subscription| 23 if subscription.subscribers.include?(owner) 24 owner.subscriptions[path] << subscription 25 end 26 end 27 end 28 end 29 end
paths()
click to toggle source
# File lib/owners/search.rb 15 def paths 16 subscriptions_by_file.keys 17 end
Private Instance Methods
attempts()
click to toggle source
# File lib/owners/search.rb 60 def attempts 61 pathnames.map(&:to_s).product(configs) 62 end
configs()
click to toggle source
# File lib/owners/search.rb 64 def configs 65 Config.for(@configs || owner_files) 66 end
owner_files()
click to toggle source
# File lib/owners/search.rb 68 def owner_files 69 trees.flat_map(&:owner_files).uniq 70 end
pathnames()
click to toggle source
# File lib/owners/search.rb 76 def pathnames 77 @files.map do |file| 78 file.prepend("./") unless file =~ RELATIVE 79 Pathname.new(file) 80 end 81 end
search(&block)
click to toggle source
# File lib/owners/search.rb 55 def search(&block) 56 results = Hash.new { |hash, key| hash[key] = [] } 57 attempts.each_with_object(results, &block) 58 end
subscribers()
click to toggle source
# File lib/owners/search.rb 33 def subscribers 34 subscriptions_by_file 35 .values 36 .flatten 37 .flat_map(&:subscribers) 38 .uniq 39 end
subscriptions()
click to toggle source
# File lib/owners/search.rb 41 def subscriptions 42 subscriptions_by_file.flat_map do |path, subscriptions| 43 [path].product(subscriptions) 44 end 45 end
subscriptions_by_file()
click to toggle source
# File lib/owners/search.rb 47 def subscriptions_by_file 48 search do |(path, config), results| 49 relative = path.sub("./", "") 50 matches = config.subscriptions(path, @shallow) 51 results[relative] += matches if matches.any? 52 end 53 end
trees()
click to toggle source
# File lib/owners/search.rb 72 def trees 73 pathnames.map { |path| Tree.new(path) } 74 end