<commit_before>STDOUT.sync = true

require "gem_suit/application/utils/gemfile"

module GemSuit
  class Application < ::Thor::Group
    module Utils

      def self.included(base)
        base.extend ClassMethods
        base.send :include, InstanceMethods
      end

      module ClassMethods
        attr_accessor :__file__

        def inherited(klass)
          klass.__file__ = caller.first[/^[^:]+/]
        end
      end

      module InstanceMethods
        attr_accessor :root_path, :validate_root_path

        def validate_root_path!(path)
          unless path.match(/rails-\d/)
            puts caller
            log "Running a #{self.class.name} instance from an invalid path: '#{path}' needs to match ".red + "/rails-\\d/".yellow
            exit
          end
        end

        def root_path
          (@root_path || (defined?(Rails) ? Rails.root : File.expand_path("../..", self.class.__file__)).to_s).tap do |path|
            validate_root_path! path if validate_root_path
            self.class.source_root = path
          end
        end

        def shared_path
          File.expand_path("../../shared", root_path)
        end

        def templates_path
          File.expand_path("../../templates", root_path)
        end

        def expand_path(path)
          Pathname.new(path).absolute? ?
            path :
            File.expand_path(path, root_path)
        end

        def original(file)
          expand_path file.gsub(/\.#{STASHED_EXT}$/, "")
        end

        def stashed(file)
          expand_path file.match(/\.#{STASHED_EXT}$/) ? file : "#{file}.#{STASHED_EXT}"
        end

        def new_file?(file)
          return false unless File.exists? expand_path(".new_files")
          root          = Pathname.new root_path<commit_msg>Being able to coop with GemSuit::Application instantiation from a dummy rails app and from the shared test directory<commit_after>STDOUT.sync = true

require "gem_suit/application/utils/gemfile"

module GemSuit
  class Application < ::Thor::Group
    module Utils

      def self.included(base)
        base.extend ClassMethods
        base.send :include, InstanceMethods
      end

      module ClassMethods
        attr_accessor :__file__

        def inherited(klass)
          klass.__file__ = caller.first[/^[^:]+/]
        end
      end

      module InstanceMethods
        attr_accessor :root_path, :validate_root_path

        def validate_root_path!(path)
          unless path.match(/rails-\d/)
            log "Running a #{self.class.name} instance from an invalid path: '#{path}' needs to match ".red + "/rails-\\d/".yellow
            exit
          end
        end

        def root_path
          (@root_path || (Rails.root if defined? Rails) || begin
            dir = File.expand_path "../..", self.class.__file__
            File.exists?("#{dir}/config/environment.rb") ? dir : Dir["#{dir}/../rails-*/dummy"].last
          end).to_s.tap do |path|
            validate_root_path! path if validate_root_path
            self.class.source_root = path
          end
        end

        def shared_path
          File.expand_path("../../shared", root_path)
        end

        def templates_path
          File.expand_path("../../templates", root_path)
        end

        def expand_path(path)
          Pathname.new(path).absolute? ?
            path :
            File.expand_path(path, root_path)
        end

        def original(file)
          expand_path file.gsub(/\.#{STASHED_EXT}$/, "")
        end

        def stashed(file)
          expand_path file.match(/\.#{STASHED_EXT}$/) ? file : "#{file}.#{STASHED_EXT}"
        end

        def new_file?(file)
          return false unless File.exists? expand_path(".new_files")
          root          = Pathname.new root_path
{'fraction_non_alphanumeric': 0.11152219873150106, 'fraction_numerical': 0.0, 'mean_word_length': 1.8805175038051751, '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': '4491949', 'n_tokens_mistral': 1107, 'n_tokens_neox': 1080, 'n_words': 250}