<commit_before>require "combi/service"
require 'yajl'
require 'yajl/json_gem' # for object.to_json, JSON.parse, etc...

module Combi
  class Bus
    attr_reader :services

    RPC_DEFAULT_TIMEOUT = 1
    RPC_MAX_POLLS = 10

    def initialize(options)
      @options = options
      @services = []
      post_initialize
    end

    def post_initialize
    end

    def add_service(service_definition, options = {})
      service = make_service_instance(service_definition)
      service.setup(self, options[:context])
      @services << service
    end

    def start!
    end

    def stop!
    end

    def restart!
      stop!
      start!
    end

    def enable(services)
      services.each do |service|
        case service
        when :queue
          require 'queue_service'
          EventMachine.next_tick do
            Combi::QueueService.start ConfigProvider.for(:amqp)
          end
        when :redis
          require 'redis'
          $redis = Redis.new ConfigProvider.for(:redis)
        when :active_record
          require 'active_record'
          ActiveRecord::Base.establish_connection ConfigProvider.for(:database)
        when :bus
          $service_bus = Combi::ServiceBus.for(:queue)
        end
      end
    end

    protected

    def make_service_instance(service_definition)
      if Combi::Service === service_definition
        service = service_definition 
      else
        service = create_service_from_module(service_definition)
      end
    end

    def create_service_from_module(a_module)
      service_class = Class.new do
        include Combi::Service
        include a_module  
      end
      service = service_class.new
    end
  end
end<commit_msg>clean up<commit_after>require "combi/service"
require 'yajl'
require 'yajl/json_gem' # for object.to_json, JSON.parse, etc...

module Combi
  class Bus
    attr_reader :services

    RPC_DEFAULT_TIMEOUT = 1
    RPC_MAX_POLLS = 10

    def initialize(options)
      @options = options
      @services = []
      post_initialize
    end

    def post_initialize
    end

    def add_service(service_definition, options = {})
      service = make_service_instance(service_definition)
      service.setup(self, options[:context])
      @services << service
    end

    def start!
    end

    def stop!
    end

    def restart!
      stop!
      start!
    end

    def enable(services)
      services.each do |service|
        case service
        when :queue
          require 'queue_service'
          EventMachine.next_tick do
            Combi::QueueService.start ConfigProvider.for(:amqp)
          end
        when :redis
          require 'redis'
          $redis = Redis.new ConfigProvider.for(:redis)
        when :active_record
          require 'active_record'
          ActiveRecord::Base.establish_connection ConfigProvider.for(:database)
        when :bus
          $service_bus = Combi::ServiceBus.for(:queue)
        end
      end
    end

    protected

    def make_service_instance(service_definition)
      if Combi::Service === service_definition
        service = service_definition
      else
        service = create_service_from_module(service_definition)
      end
    end

    def create_service_from_module(a_module)
      service_class = Class.new do
        include Combi::Service
        include a_module
      end
      service = service_class.new
    end
  end
end
{'fraction_non_alphanumeric': 0.06941176470588235, 'fraction_numerical': 0.0017647058823529412, 'mean_word_length': 2.242135367016206, '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': '1421991', 'n_tokens_mistral': 982, 'n_tokens_neox': 952, 'n_words': 230}