<commit_before>#! /bin/env ruby

PLUGIN_DIR = File.dirname(__FILE__) + '/..'


class OverridingMethodChecker

  FILES_WITH_DIR_TO_CHECK = [
    %w(user.rb             app/models     ),
    %w(users_controller.rb app/controllers),
  ]

  ROOT_DIRS_AND_NAMESPACES = [
    ["."                 , ""              ],
    [PLUGIN_DIR + "/lib" , "user_auth_kuma"],
  ]

  def check
    FILES_WITH_DIR_TO_CHECK.each do |file, dir|
      ROOT_DIRS_AND_NAMESPACES.each do |root_dir, namespace|
        file_full = File.join(root_dir, dir, namespace, file)
        methods = user_defined_methods(file_full)
        puts "#{file_full} : #{methods.map { |m| "  " + m.to_s }.join("\n")}"
      end
    end
  end

  private

    RE_METHOD = /\A\s*def\s+((?:self\.)?\w+\??)/

    def user_defined_methods(file)
      methods = Array.new
      File.open(file, 'r') do |fd|
        fd.each do |line|
          if line =~ RE_METHOD<commit_msg>Almost completed OverridingMethodChecker<commit_after>#! /bin/env ruby


class OverridingMethodChecker

  PLUGIN_LIB_DIR = File.dirname(__FILE__) + '/../lib'

  FILENAMES_WITH_DIR_TO_CHECK = [
    %w(user.rb             app/models     ),
    %w(users_controller.rb app/controllers),
  ]

  H_ROOT_DIRS_AND_NAMESPACES = {
    overriding: ["."           , ""              ],
    overridden: [PLUGIN_LIB_DIR, "user_auth_kuma"],
  }

  INDENT = "  "

  def check
    FILENAMES_WITH_DIR_TO_CHECK.each do |filename, dir|
      h_methods = Hash.new
      H_ROOT_DIRS_AND_NAMESPACES.each do |name, root_and_ns|
        root_dir, namespace = root_and_ns
        full_filename = File.join(root_dir, dir, namespace, filename)
        h_methods[name] = user_defined_methods(full_filename)
      end

      overriding_filename = File.join(dir, filename)
      overriding_methods = Array.new
      h_methods[:overridden].each do |method|
        overriding_methods << method if h_methods[:overriding].include?(method)
      end
      unless overriding_methods.empty?
        puts "The following methods in '#{overriding_filename}' are overriding the ones in the plugin"
        puts overriding_methods.map { |method| INDENT + method.to_s }.join("\n")
      end
    end
  end

  private

    RE_METHOD = /\A\s*def\s+((?:self\.)?\w+\??)/

    def user_defined_methods(filename)
      methods = Array.new
      File.open(filename, 'r') do |fd|
        fd.each do |line|
          if line =~ RE_METHOD
{'fraction_non_alphanumeric': 0.12380556709597008, 'fraction_numerical': 0.0, 'mean_word_length': 2.551622418879056, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '3380609', 'n_tokens_mistral': 868, 'n_tokens_neox': 836, 'n_words': 156}