<commit_before>require 'set'
require 'dm-core'

module DataMapper
  module Visualizer
    #
    # Defines the paths and directories to load for a DataMapper project.
    #
    class Project

      # The directories to include
      attr_reader :include_dirs

      # The paths to require
      attr_reader :require_paths

      # The path glob patterns to require
      attr_reader :require_globs

      #
      # Creates a new project.
      #
      # @param [Hash] options
      #   Additional options.
      #
      # @option options [Array] :include
      #   The directories to include into the `$LOAD_PATH` global variable.
      #
      # @option options [Array] :require
      #   The paths to require.
      #
      # @option options [Array] :require_all
      #   The path globs to require.
      #
      def initialize(options={})
        @include_dirs = Set[]
        @require_paths = Set[]
        @require_globs = Set[]

        if options[:include]
          options[:include].each do |dir|
            @include_dirs << File.expand_path(dir)
          end
        end

        if options[:require]
          @require_paths += options[:require]
        end

        if options[:require_all]
          @require_globs += options[:require_all]
        end
      end

      #
      # Activates the project by adding it's include directories to the
      # `$LOAD_PATH` global variable.
      #
      # @return [true]
      #
      def activate!
        @include_dirs.each do |dir|
          $LOAD_PATH << dir if File.directory?(dir)
        end

        return true
      end

      #
      # De-activates the project by removing it's include directories to the
      # `$LOAD_PATH` global variable.
      #
      # @return [true]
      #
      def deactivate!
        $LOAD_PATH.reject! { |dir| @include_dirs.include?(dir) }
        return true
      end

      #
      # Attempts to load all of the projects files.
      #
      # @return [true]
      #
      def load!
        activate!<commit_msg>Add support for loading dependencies using Bundler if a Gemfile exists.<commit_after>require 'set'
require 'dm-core'

module DataMapper
  module Visualizer
    #
    # Defines the paths and directories to load for a DataMapper project.
    #
    class Project

      # The directories to include
      attr_reader :include_dirs

      # The paths to require
      attr_reader :require_paths

      # The path glob patterns to require
      attr_reader :require_globs

      #
      # Creates a new project.
      #
      # @param [Hash] options
      #   Additional options.
      #
      # @option options [Array] :include
      #   The directories to include into the `$LOAD_PATH` global variable.
      #
      # @option options [Array] :require
      #   The paths to require.
      #
      # @option options [Array] :require_all
      #   The path globs to require.
      #
      def initialize(options={})
        @include_dirs = Set[]
        @require_paths = Set[]
        @require_globs = Set[]

        if options[:include]
          options[:include].each do |dir|
            @include_dirs << File.expand_path(dir)
          end
        end

        if options[:require]
          @require_paths += options[:require]
        end

        if options[:require_all]
          @require_globs += options[:require_all]
        end
      end

      #
      # Activates the project by adding it's include directories to the
      # `$LOAD_PATH` global variable.
      #
      # @return [true]
      #
      def activate!
        @include_dirs.each do |dir|
          $LOAD_PATH << dir if File.directory?(dir)
        end

        if File.directory?('Gemfile')
          begin
            require 'bundler'
          rescue LoadError => e
            STDERR.puts "Gemfile exists, but bundler is not installed"
            STDERR.puts "Run `gem install bundler` to install bundler."
          end

          begin
            Bundler.setup()
          rescue Bundler::BundleError => e
            STDERR.puts e.message
            STDERR.puts "Run `bundle install` to install missing gems"
          end
        end

        return true
      end

      #
      # De-activates the project by removing it's include directories to the
      # `$LOAD_PATH` global variable.
      #
      # @return [true]
      #
      def deactivate!
        $LOAD_PATH.reject! { |dir| @include_dirs.include?(dir) }
        return true
      end

      #
      # Attempts to load all of the projects files.
      #
      # @return [true]
      #
      def load!
        activate!
{'fraction_non_alphanumeric': 0.08244041110868139, 'fraction_numerical': 0.0, 'mean_word_length': 1.7487980769230769, 'pattern_counts': {'":': 0, '<': 11, '<?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': '491375', 'n_tokens_mistral': 1304, 'n_tokens_neox': 1265, 'n_words': 395}