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.



197
198
199
# File 'lib/adhearsion/voip/dial_plan.rb', line 197

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.



163
164
165
# File 'lib/adhearsion/voip/dial_plan.rb', line 163

def default_dial_plan_file_name
  @default_dial_plan_file_name
end

Class Method Details

.load(dial_plan_as_string) ⇒ Object



165
166
167
168
169
170
171
# File 'lib/adhearsion/voip/dial_plan.rb', line 165

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



173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/adhearsion/voip/dial_plan.rb', line 173

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
  new.tap do |loader|
    files.each do |file|
      loader.load file
    end
  end
end

Instance Method Details

#contextsObject



201
202
203
# File 'lib/adhearsion/voip/dial_plan.rb', line 201

def contexts
  @context_collector.contexts
end

#load(dialplan_file) ⇒ Object



205
206
207
208
209
# File 'lib/adhearsion/voip/dial_plan.rb', line 205

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