Sha256: 169c55bbb447bef26338f6df45c69d8d51c34b7ee4440fc022b5876b9f867fb8

Contents?: true

Size: 1.3 KB

Versions: 6

Compression:

Stored size: 1.3 KB

Contents

require 'adhearsion/voip/asterisk'

module Adhearsion
  class Initializer    
    class RailsInitializer
      
      cattr_accessor :rails_root, :config, :environment
      class << self
        
        def start
          ahn_config       = Adhearsion::AHN_CONFIG
          self.config      = ahn_config.rails
          self.rails_root  = config.rails_root 
          self.environment = config.environment
          raise "You cannot enable the database and Rails at the same time!" if ahn_config.database_enabled?
          raise "Error loading Rails environment in #{rails_root.inspect}. "  +
                "It's not a directory!" unless File.directory?(rails_root)
          load_rails
          if defined? ActiveRecord
            ActiveRecord::Base.allow_concurrency = true
            Events.register_callback([:asterisk, :before_call]) do
              ActiveRecord::Base.verify_active_connections!
            end
          end
        end
        
        private
        
        def load_rails
          environment_file = File.expand_path(rails_root + "/config/environment.rb")
          raise "There is no config/environment.rb file!" unless File.exists?(environment_file)
          ENV['RAILS_ENV'] = environment.to_s
          require environment_file
        end
        
      end
      
    end
  end
end

Version data entries

6 entries across 6 versions & 4 rubygems

Version Path
eric-adhearsion-0.8.0 lib/adhearsion/initializer/rails.rb
jicksta-adhearsion-0.7.999 lib/adhearsion/initializer/rails.rb
jicksta-adhearsion-0.8.0 lib/adhearsion/initializer/rails.rb
sevenscale-adhearsion-0.8.0 lib/adhearsion/initializer/rails.rb
adhearsion-0.8.0 lib/adhearsion/initializer/rails.rb
adhearsion-0.8.1 lib/adhearsion/initializer/rails.rb