<commit_before># frozen_string_literal: true

require 'tzispa/utils/string'

module Tzispa

  class Domain
    using Tzispa::Utils

    attr_reader :name

    def initialize(name)
      @name = name
      @root = "#{Tzispa::Environment.instance.root}/#{Tzispa::Environment.instance.apps_path}"
      instance_eval "module ::#{name.to_s.capitalize}; end"
    end

    def path
      @path ||= root % name.to_s.downcase
    end

    def require(file)
      Kernel.require "#{path}/#{file}"
    end

    def load(file)
      Kernel.load "#{path}/#{file}.rb"
    end

    def require_dir(dir = nil)
      rqpath = dir ? "#{path}/#{dir}" : path.to_s
      Dir["#{rqpath}/*.rb"].each do |file|
        name = file.split('/').last.split('.').first
        Kernel.require "#{rqpath}/#{name}"
      end
    end

    def load_dir(dir = nil)
      rqpath = dir ? "#{path}/#{dir}" : path.to_s
      Dir["#{rqpath}/*.rb"].each do |file|
        name = file.split('/').last
        Kernel.load "#{rqpath}/#{name}"
      end
    end

    def include(cmod)
      name.to_s.capitalize.constantize.include cmod
    end

    def self.require(domain, file)
      new(name: domain).require(file)
    end

    def self.load(domain, file)
      new(name: domain).load(file)
    end

    protected

    attr_reader :root
  end

end<commit_msg>added domain setup method<commit_after># frozen_string_literal: true

require 'tzispa/utils/string'

module Tzispa

  class Domain
    using Tzispa::Utils

    attr_reader :name, :root

    def initialize(name)
      @name = name
      @root = "#{Tzispa::Environment.instance.root}/#{Tzispa::Environment.instance.apps_path}"
      instance_eval "module ::#{name.to_s.capitalize}; end"
    end

    def setup
      require_dir
      require_dir 'helpers'
      require_dir 'services'
      require_dir 'api'
      require_dir 'middleware'
    end

    def path
      @path ||= root % name.to_s.downcase
    end

    def require(file)
      Kernel.require "#{path}/#{file}"
    end

    def load(file)
      Kernel.load "#{path}/#{file}.rb"
    end

    def require_dir(dir = nil)
      rqpath = dir ? "#{path}/#{dir}" : path.to_s
      Dir["#{rqpath}/*.rb"].each do |file|
        name = file.split('/').last.split('.').first
        Kernel.require "#{rqpath}/#{name}"
      end
    end

    def load_dir(dir = nil)
      rqpath = dir ? "#{path}/#{dir}" : path.to_s
      Dir["#{rqpath}/*.rb"].each do |file|
        name = file.split('/').last
        Kernel.load "#{rqpath}/#{name}"
      end
    end

    def include(cmod)
      name.to_s.capitalize.constantize.include cmod
    end

    def self.require(domain, file)
      new(name: domain).require(file)
    end

    def self.load(domain, file)
      new(name: domain).load(file)
    end
  end

end
{'fraction_non_alphanumeric': 0.15115440115440115, 'fraction_numerical': 0.0, 'mean_word_length': 2.4192355117139335, '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': '7350633', 'n_tokens_mistral': 981, 'n_tokens_neox': 958, 'n_words': 200}