Sha256: 8a33b3603b0cc31c465abc4d7bc39cff57f4015c84195249c4987495a0f311ab

Contents?: true

Size: 900 Bytes

Versions: 1

Compression:

Stored size: 900 Bytes

Contents

module Owners
  # Accepts an array of file paths and returns an array of
  # owners that have subscribed to the specified files.
  #
  # @api private
  class Search
    def initialize(files)
      @files = files
    end

    def owners
      search do |(path, config), results|
        owners = config.owners(path.to_s)
        results.merge(owners) if owners
      end
    end

    private

    def search(&block)
      attempts.each_with_object(SortedSet.new, &block).to_a
    end

    def attempts
      paths.product(configs)
    end

    def configs
      subscriptions.map { |file| Config.new(file) }
    end

    def subscriptions
      trees.flat_map(&:owner_files).uniq
    end

    def trees
      paths.map { |path| Tree.new(path) }
    end

    def paths
      @files.map do |file|
        file.prepend("./") unless file =~ /^\.?\//
        Pathname.new(file)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
owners-0.0.3 lib/owners/search.rb