Class: Adhearsion::VoIP::Asterisk::ConfigurationManager

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ ConfigurationManager

Returns a new instance of ConfigurationManager.



18
19
20
# File 'lib/adhearsion/voip/asterisk/config_manager.rb', line 18

def initialize(filename)
  @filename = filename
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



16
17
18
# File 'lib/adhearsion/voip/asterisk/config_manager.rb', line 16

def filename
  @filename
end

Class Method Details

.normalize_configuration(file_contents) ⇒ Object



8
9
10
11
12
13
# File 'lib/adhearsion/voip/asterisk/config_manager.rb', line 8

def normalize_configuration(file_contents)
  # cat sip.conf | sed -e 's/\s*;.*$//g' | sed -e '/^;.*$/d' | sed -e '/^\s*$/d'
  file_contents.split(/\n+/).map do |line|
    line.sub(/;.+$/, '').strip
  end.join("\n").squeeze("\n")
end

Instance Method Details

#[](section_name) ⇒ Object



26
27
28
29
# File 'lib/adhearsion/voip/asterisk/config_manager.rb', line 26

def [](section_name)
  result = sections.find { |(name, *rest)| section_name == name }
  result.last if result
end

#delete_section(section_name) ⇒ Object



31
32
33
# File 'lib/adhearsion/voip/asterisk/config_manager.rb', line 31

def delete_section(section_name)
  sections.reject! { |(name, *rest)| section_name == name }
end

#new_section(name, properties = {}) ⇒ Object



35
36
37
# File 'lib/adhearsion/voip/asterisk/config_manager.rb', line 35

def new_section(name, properties={})
  sections << [name, properties]
end

#sectionsObject



22
23
24
# File 'lib/adhearsion/voip/asterisk/config_manager.rb', line 22

def sections
  @sections ||= read_configuration
end