<commit_before>require 'pom/core_ext/pathname'
#require 'pom/core_ext/try_dup'

module POM

  #
  class Reqfile
    include Enumerable

    # TODO: Narrow naming.
    def self.filename
      ['REQUIRE', 'Require', '.require']
    end

    #
    def self.find(root)
      root = Pathname.new(root)
      pattern = '{' + filename.join(',') + '}{,.yml,.yaml}'
      root.glob(pattern).first
    end

    #
    attr :file

    #
    attr :dependencies

    #
    attr :conflicts

    #
    attr :replaces

    #
    attr :provides

    #
    attr :optional

    #
    def initialize(root)
      @root = Pathname.new(root)
      @file = self.class.find(root)

      @dependencies = []

      #@production  = []

      if @file && @file.exist?
        data = YAML.load(File.new(@file))
        data.each do |group, deps|
          deps.each do |pkg|
            dep = Dependency.new(pkg, group)
            @dependencies << dep
          end
        end
      end
    end

    #
    def each(&block)
      dependencies.each(&block)
    end

    #
    def size
      dependencies.size
    end

    #
    def requirements
      dependencies.reject{ |dep| dep.optional? }
    end

    #
    def development
      dependencies.select{ |dep| dep.development? }
    end

    # TODO: Reqfile needs a specialized to_yaml

    # TODO: What about production vs. runtime?
<commit_msg>minor: add debug warning if no REQUIRE file<commit_after>require 'pom/core_ext/pathname'
#require 'pom/core_ext/try_dup'

module POM

  # Access to REQUIRE file.
  #
  class Reqfile
    include Enumerable

    # TODO: Narrow naming.
    def self.filename
      ['REQUIRE', 'Require', '.require']
    end

    #
    def self.find(root)
      root = Pathname.new(root)
      pattern = '{' + filename.join(',') + '}{,.yml,.yaml}'
      root.glob(pattern).first
    end

    #
    attr :file

    #
    attr :dependencies

    #
    attr :conflicts

    #
    attr :replaces

    #
    attr :provides

    #
    attr :optional

    #
    def initialize(root)
      @root = Pathname.new(root)
      @file = self.class.find(root)

      @dependencies = []

      #@production  = []

      if @file && @file.exist?
        data = YAML.load(File.new(@file))
        data.each do |group, deps|
          deps.each do |pkg|
            dep = Dependency.new(pkg, group)
            @dependencies << dep
          end
        end
      else
        warn "No REQUIRE file at #{root}" if $DEBUG
      end
    end

    #
    def each(&block)
      dependencies.each(&block)
    end

    #
    def size
      dependencies.size
    end

    #
    def requirements
      dependencies.reject{ |dep| dep.optional? }
    end

    #
    def development
      dependencies.select{ |dep| dep.development? }
    end

    # TODO: Reqfile needs a specialized to_yaml

    # TODO: What about production vs. runtime?

{'fraction_non_alphanumeric': 0.11313485113835377, 'fraction_numerical': 0.0, 'mean_word_length': 1.8305252725470764, 'pattern_counts': {'":': 0, '<': 7, '<?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': '6770232', 'n_tokens_mistral': 964, 'n_tokens_neox': 901, 'n_words': 222}