<commit_before>#! /usr/bin/env ruby
# -*- coding: UTF-8 -*-

# brew-which-update: DB updater script for `brew-which-formula`
#
# Usage:
#
#   brew which-update <DB file>
#

require "formula"
require "pathname"

class ExecutablesDB
  attr_accessor :exes

  def initialize(filename)
    @filename = filename
    @exes = {}

    if File.file? @filename
      File.new(@filename).each do |line|
        formula, exes_line = line.split(":")
        (@exes[formula] ||= []).concat exes_line.split(" ")
      end
    end
  end

  def update_from(name, path)
    @exes[name] = []
    Dir["#{path}/{bin,sbin}/*"].uniq.each do |f|
      next unless File.executable? f
      @exes[name] << Pathname.new(f).basename.to_s
    end
    @exes[name].uniq!
  end

  def update!
    Formula.each do |f|
      tap = f.tap? #&& f.tap !~ %r(^homebrew/)
      name = f.full_name

      # TODO check that the formula is not outdated
      update_from name, f.prefix if f.installed?

      if tap
        origin = f.name
        if !@exes[name] && @exes[origin]
          @exes[name] = @exes[origin]<commit_msg>Don't check non-official taps<commit_after>#! /usr/bin/env ruby
# -*- coding: UTF-8 -*-

# brew-which-update: DB updater script for `brew-which-formula`
#
# Usage:
#
#   brew which-update <DB file>
#

require "formula"
require "pathname"

class ExecutablesDB
  attr_accessor :exes

  def initialize(filename)
    @filename = filename
    @exes = {}

    if File.file? @filename
      File.new(@filename).each do |line|
        formula, exes_line = line.split(":")
        (@exes[formula] ||= []).concat exes_line.split(" ")
      end
    end
  end

  def update_from(name, path)
    @exes[name] = []
    Dir["#{path}/{bin,sbin}/*"].uniq.each do |f|
      next unless File.executable? f
      @exes[name] << Pathname.new(f).basename.to_s
    end
    @exes[name].uniq!
  end

  def update!
    Formula.each do |f|
      next if f.tap? && !f.tap.include?("omebrew/")
      name = f.full_name

      # TODO check that the formula is not outdated
      update_from name, f.prefix if f.installed?

      if f.tap?
        origin = f.name
        if !@exes[name] && @exes[origin]
          @exes[name] = @exes[origin]
{'fraction_non_alphanumeric': 0.1534608378870674, 'fraction_numerical': 0.0009107468123861566, 'mean_word_length': 2.5264847512038524, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5866362', 'n_tokens_mistral': 822, 'n_tokens_neox': 791, 'n_words': 188}