<commit_before>require 'adhearsion/voip/asterisk'
module Adhearsion
  class Initializer
    
    class AsteriskInitializer
      
      cattr_accessor :config, :agi_server, :ami_server
      class << self
        
        def start
          self.config     = Adhearsion::AHN_CONFIG.asterisk
          self.agi_server = initialize_agi
          self.ami_server = initialize_ami if config.ami_enabled?
          join_server_thread_after_initialized
        end

        def stop
          agi_server.stop
          ami_server.disconnect! if ami_server
        end

        private

        def initialize_agi
          Adhearsion::VoIP::Asterisk::AGI::Server.new :host => config.listening_host,
                                                      :port => config.listening_port
        end
        
        def initialize_ami
          options = ami_options
          start_ami_after_initialized
          Adhearsion::VoIP::Asterisk::AMI.new options[:username], options[:password],
                                              options[:host], :port => options[:port],
                                              :events => options[:events]
        end
        
        def ami_options
          %w(host port username password events).inject({}) do |options, property|
            options[property.to_sym] = config.ami.send property
            options
          end
        end
        
        def join_server_thread_after_initialized
          Adhearsion::Hooks::AfterInitialized.create_hook { agi_server.start }
          Adhearsion::Hooks::ThreadsJoinedAfterInitialized.create_hook { agi_server.join }
        end
        
        def start_ami_after_initialized
          Adhearsion::Hooks::AfterInitialized.create_hook do
            ami_server.connect!
          end
        end

      end
    end
    
  end
end<commit_msg>Renamed the ami_server property to ami_client in lib/adhearsion/initializer/asterisk.rb<commit_after>require 'adhearsion/voip/asterisk'
module Adhearsion
  class Initializer
    
    class AsteriskInitializer
      
      cattr_accessor :config, :agi_server, :ami_client
      class << self
        
        def start
          self.config     = Adhearsion::AHN_CONFIG.asterisk
          self.agi_server = initialize_agi
          self.ami_client = initialize_ami if config.ami_enabled?
          join_server_thread_after_initialized
        end

        def stop
          agi_server.stop
          ami_client.disconnect! if ami_client
        end

        private

        def initialize_agi
          Adhearsion::VoIP::Asterisk::AGI::Server.new :host => config.listening_host,
                                                      :port => config.listening_port
        end
        
        def initialize_ami
          options = ami_options
          start_ami_after_initialized
          Adhearsion::VoIP::Asterisk::AMI.new options[:username], options[:password],
                                              options[:host], :port => options[:port],
                                              :events => options[:events]
        end
        
        def ami_options
          %w(host port username password events).inject({}) do |options, property|
            options[property.to_sym] = config.ami.send property
            options
          end
        end
        
        def join_server_thread_after_initialized
          Adhearsion::Hooks::AfterInitialized.create_hook { agi_server.start }
          Adhearsion::Hooks::ThreadsJoinedAfterInitialized.create_hook { agi_server.join }
        end
        
        def start_ami_after_initialized
          Adhearsion::Hooks::AfterInitialized.create_hook do
            ami_client.connect!
          end
        end

      end
    end
    
  end
end
{'fraction_non_alphanumeric': 0.06463675213675214, 'fraction_numerical': 0.0, 'mean_word_length': 1.6981268011527377, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6631283', 'n_tokens_mistral': 983, 'n_tokens_neox': 979, 'n_words': 186}