<commit_before>require 'active_record'
require 'drb/drb'

module ActiveDomain
  class Server

    def self.run(options = nil)
      self.new(options).run
    end

    def initialize(new_options = nil)
      self.options = new_options.deep_symbolize_keys! unless new_options.nil?
    end

    def run
      ActiveRecord::Base.establish_connection options[:domain_database]
      ActiveEvent::EventServer.start options
      drb_uri = URI::Generic.build(options[:drb_server]).to_s
      DRb.start_service(drb_uri, domain)
      DRb.thread.join
    rescue Interrupt
      puts 'Catching Interrupt'
    end

    def env
      @env = ENV['DOMAIN_ENV'] || ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development'
    end

    def options
      @options ||= parse_options(ARGV)
    end

    def domain
      @domain ||= ActiveDomain::CommandRoutes.new
    end

    cattr_accessor :base_path
    cattr_accessor :config_file

    def config_file
      self.class.config_file || File.expand_path('config/disco.yml', base_path)
    end

    private

    attr_writer :options
    attr_writer :domain

    def default_options
      {
          drb_server: {
              scheme: 'druby',
              hostname: '127.0.0.1',
              port: 8787,
          },
          domain_database: {
              adapter: 'sqlite3',
              database: File.expand_path('db/domain.sqlite3', base_path)
          },
          event_connection: {
              scheme: 'amqp',
              userinfo: nil,
              host: '127.0.0.1',
              port: 9797,
          },
          event_exchange: 'events'
      }
    end

    def parse_options(args)
      options = default_options
      options.merge! YAML.load_file(config_file)[env].deep_symbolize_keys! unless config_file.blank?
    end
  end<commit_msg>added drb config support<commit_after>require 'active_record'
require 'drb/drb'

module ActiveDomain
  class Server

    def self.run(options = nil)
      self.new(options).run
    end

    def initialize(new_options = nil)
      self.options = new_options.deep_symbolize_keys! unless new_options.nil?
    end

    def run
      ActiveRecord::Base.establish_connection options[:domain_database]
      ActiveEvent::EventServer.start options
      drb_uri = URI::Generic.build(options[:drb_server]).to_s
      DRb.start_service(drb_uri, domain, options.fetch(:drb_config, {}))
      DRb.thread.join
    rescue Interrupt
      puts 'Catching Interrupt'
    end

    def env
      @env = ENV['DOMAIN_ENV'] || ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development'
    end

    def options
      @options ||= parse_options(ARGV)
    end

    def domain
      @domain ||= ActiveDomain::CommandRoutes.new
    end

    cattr_accessor :base_path
    cattr_accessor :config_file

    def config_file
      self.class.config_file || File.expand_path('config/disco.yml', base_path)
    end

    private

    attr_writer :options
    attr_writer :domain

    def default_options
      {
          drb_server: {
              scheme: 'druby',
              hostname: '127.0.0.1',
              port: 8787,
          },
          drb_config: {
              verbose: true,
          },
          domain_database: {
              adapter: 'sqlite3',
              database: File.expand_path('db/domain.sqlite3', base_path)
          },
          event_connection: {
              scheme: 'amqp',
              userinfo: nil,
              host: '127.0.0.1',
              port: 9797,
          },
          event_exchange: 'events'
      }
    end

    def parse_options(args)
      options = default_options
      options.merge! YAML.load_file(config_file)[env].deep_symbolize_keys! unless config_file.blank?
    end
  end
{'fraction_non_alphanumeric': 0.09835179681167253, 'fraction_numerical': 0.011888678735476898, 'mean_word_length': 2.1479591836734695, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, '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': '5155343', 'n_tokens_mistral': 1194, 'n_tokens_neox': 1136, 'n_words': 222}