<commit_before># -*- coding: utf-8 -*-
require "rake_shared_context/version"
require "rake"
require "pathname"

class RakeSharedContext
  class << self
    def root_dir
      return @root_dir if @root_dir

      if defined? Rails
        Rails.root
      elsif defined? Padrino
        Pathname.new(Padrino.root)
      else
        Pathname.pwd
      end
    end

    def root_dir=(dir)
      @root_dir = Pathname.new(dir)
    end

    def rake_dir
      return @rake_dir if @rake_dir

      root_dir.join('lib', 'tasks')
    end

    def rake_dir=(dir)
      @rake_dir = Pathname.new(dir)
    end
  end
end

begin
  require "rspec/core"
  RSpec.shared_context "rake" do
    let(:rake)      { Rake::Application.new }
    let(:task_name) { self.class.top_level_description }
    subject         { rake[task_name] }

    before do
      loaded_files = []
      Rake.application = rake
      rake_dir = RakeSharedContext.rake_dir
      rake_files = File.join(rake_dir, "**", "*.rake")

      Dir.glob(rake_files).each do |task|
        filename_without_ext = File.basename(task.sub(/.rake$/, ''))
        Rake.application.rake_require(filename_without_ext, [File.dirname(task).to_s], loaded_files)
      end

      Rake::Task.define_task(:environment)
    end
  end
rescue LoadError
end<commit_msg>🐛 sort rake file load order<commit_after># -*- coding: utf-8 -*-
require "rake_shared_context/version"
require "rake"
require "pathname"

class RakeSharedContext
  class << self
    def root_dir
      return @root_dir if @root_dir

      if defined? Rails
        Rails.root
      elsif defined? Padrino
        Pathname.new(Padrino.root)
      else
        Pathname.pwd
      end
    end

    def root_dir=(dir)
      @root_dir = Pathname.new(dir)
    end

    def rake_dir
      return @rake_dir if @rake_dir

      root_dir.join('lib', 'tasks')
    end

    def rake_dir=(dir)
      @rake_dir = Pathname.new(dir)
    end
  end
end

begin
  require "rspec/core"
  RSpec.shared_context "rake" do
    let(:rake)      { Rake::Application.new }
    let(:task_name) { self.class.top_level_description }
    subject         { rake[task_name] }

    before do
      loaded_files = []
      Rake.application = rake
      rake_dir = RakeSharedContext.rake_dir
      rake_files = File.join(rake_dir, "**", "*.rake")

      Dir.glob(rake_files).sort.each do |task|
        filename_without_ext = File.basename(task.sub(/.rake$/, ''))
        Rake.application.rake_require(filename_without_ext, [File.dirname(task).to_s], loaded_files)
      end

      Rake::Task.define_task(:environment)
    end
  end
rescue LoadError
end
{'fraction_non_alphanumeric': 0.10885396703717899, 'fraction_numerical': 0.0007665772326561902, 'mean_word_length': 2.5704514363885087, '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': '486737', 'n_tokens_mistral': 906, 'n_tokens_neox': 882, 'n_words': 182}