Class: Adhearsion::DialPlan::Loader

Inherits:
Object
  • Object
show all
Defined in:
lib/adhearsion/voip/dial_plan.rb

Defined Under Namespace

Classes: ContextNameCollector

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLoader

Returns a new instance of Loader.



165
166
167
# File 'lib/adhearsion/voip/dial_plan.rb', line 165

def initialize
  @context_collector = ContextNameCollector.new
end

Class Attribute Details

.default_dial_plan_file_nameObject

Returns the value of attribute default_dial_plan_file_name.



131
132
133
# File 'lib/adhearsion/voip/dial_plan.rb', line 131

def default_dial_plan_file_name
  @default_dial_plan_file_name
end

Class Method Details

.load(dial_plan_as_string) ⇒ Object



133
134
135
136
137
138
139
# File 'lib/adhearsion/voip/dial_plan.rb', line 133

def load(dial_plan_as_string)
  string_io = StringIO.new dial_plan_as_string
  def string_io.path
    "(eval)"
  end
  load_dialplans string_io
end

.load_dialplans(*files) ⇒ Object



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/adhearsion/voip/dial_plan.rb', line 141

def load_dialplans(*files)
  files = Adhearsion::AHN_CONFIG.files_from_setting("paths", "dialplan") if files.empty?
  files = Array files
  files.map! do |file|
    case file
      when File, StringIO
        file
      when String
        File.new file
      else
        raise ArgumentError, "Unrecognized type of file #{file.inspect}"
    end
  end
  returning new do |loader|
    files.each do |file|
      loader.load file
    end
  end
end

Instance Method Details

#contextsObject



169
170
171
# File 'lib/adhearsion/voip/dial_plan.rb', line 169

def contexts
  @context_collector.contexts
end

#load(dialplan_file) ⇒ Object



173
174
175
176
177
# File 'lib/adhearsion/voip/dial_plan.rb', line 173

def load(dialplan_file)
  dialplan_code = dialplan_file.read
  @context_collector.instance_eval(dialplan_code, dialplan_file.path)
  nil
end