Module: Adhearsion::VoIP::DSL::Dialplan::DialplanParser

Defined in:
lib/adhearsion/voip/dsl/dialplan/parser.rb

Overview

TODO: This is obsolete, but we still need it for Freeswitch until we port that to the new 0.8.0 APIs

Class Method Summary collapse

Class Method Details

.get_contextsObject

TODO: separate into smaller pieces



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/adhearsion/voip/dsl/dialplan/parser.rb', line 16

def self.get_contexts
  envelope = ContextsEnvelope.new

  dialplans = AHN_CONFIG.files_from_setting "paths", "dialplan"
  ahn_log.dialplan.warn "No dialplan files were found!" if dialplans.empty?

  {}.tap do |contexts|
    dialplans.each do |file|
      raise "Dialplan file #{file} does not exist!" unless File.exists? file
      envelope.instance_eval do
        eval File.read(file)
      end
      current_contexts = envelope.parsed_contexts
      current_contexts.each_pair do |name, block|
        if contexts.has_key? name
          warn %'Dialplan context "#{name}" exists in both #{contexts[name].file} and #{file}.' +
               %' Using the "#{name}" context from #{contexts[name].file}.'
        else
          contexts[name] = OpenStruct.new.tap do ||
            .file  = file
            .name  = name
            .block = block
          end
        end
      end
    end
  end
end