<commit_before>require "bundler"

module LicenseFinder
  class Bundle
    attr_writer :ignore_groups

    def self.current_gems(config)
      new(config).gems
    end

    def initialize(config=nil)
      @definition = Bundler::Definition.build(gemfile_path, lockfile_path, nil)
      @config ||= config
    end

    def gems
      return @gems if @gems

      @gems ||= definition.specs_for(included_groups).map do |spec|
        dependency = dependencies.detect { |dep| dep.name == spec.name }

        BundledGem.new(spec, dependency)
      end

      @gems.each do |gem|
        gem.children = children_for(gem)
      end

      @gems
    end

    private
    attr_reader :definition

    def ignore_groups
      @ignore_groups ||= @config.ignore_groups
    end

    def dependencies
      @dependencies ||= definition.dependencies
    end

    def included_groups
      definition.groups - ignore_groups.map(&:to_sym)
    end

    def gemfile_path
      Pathname.new("Gemfile").expand_path
    end

    def lockfile_path
      gemfile_path.dirname.join('Gemfile.lock')
    end

    def children_for(gem)
      gem_names = gems.map { |gem| gem.name.split(" ")[0] }
      gem.spec.dependencies.map(&:name).select { |name| gem_names.include?(name) }
    end
  end
end
<commit_msg>Bundle can accept a bundler definition (LicenseAudit)<commit_after>require "bundler"

module LicenseFinder
  class Bundle
    attr_writer :ignore_groups

    def self.current_gems(config, bundler_definition=nil)
      new(config, bundler_definition).gems
    end

    def initialize(config=nil, bundler_definition=nil)
      @definition = bundler_definition || Bundler::Definition.build(gemfile_path, lockfile_path, nil)
      @config ||= config
    end

    def gems
      return @gems if @gems

      @gems ||= definition.specs_for(included_groups).map do |spec|
        dependency = dependencies.detect { |dep| dep.name == spec.name }

        BundledGem.new(spec, dependency)
      end

      @gems.each do |gem|
        gem.children = children_for(gem)
      end

      @gems
    end

    private
    attr_reader :definition

    def ignore_groups
      @ignore_groups ||= @config.ignore_groups
    end

    def dependencies
      @dependencies ||= definition.dependencies
    end

    def included_groups
      definition.groups - ignore_groups.map(&:to_sym)
    end

    def gemfile_path
      Pathname.new("Gemfile").expand_path
    end

    def lockfile_path
      gemfile_path.dirname.join('Gemfile.lock')
    end

    def children_for(gem)
      gem_names = gems.map { |gem| gem.name.split(" ")[0] }
      gem.spec.dependencies.map(&:name).select { |name| gem_names.include?(name) }
    end
  end
end

{'fraction_non_alphanumeric': 0.09762435040831477, 'fraction_numerical': 0.0007423904974016332, 'mean_word_length': 2.7430555555555554, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2201552', 'n_tokens_mistral': 874, 'n_tokens_neox': 822, 'n_words': 182}