Class: Adhearsion::Asterisk::ConfigurationManager
- Inherits:
-
Object
- Object
- Adhearsion::Asterisk::ConfigurationManager
- Defined in:
- lib/adhearsion/asterisk/config_manager.rb
Instance Attribute Summary (collapse)
-
- (Object) filename
readonly
Returns the value of attribute filename.
Class Method Summary (collapse)
Instance Method Summary (collapse)
- - (Object) [](section_name)
- - (Object) delete_section(section_name)
-
- (ConfigurationManager) initialize(filename)
constructor
A new instance of ConfigurationManager.
- - (Object) new_section(name, properties = {})
- - (Object) sections
Constructor Details
- (ConfigurationManager) initialize(filename)
A new instance of ConfigurationManager
18 19 20 |
# File 'lib/adhearsion/asterisk/config_manager.rb', line 18 def initialize(filename) @filename = filename end |
Instance Attribute Details
- (Object) filename (readonly)
Returns the value of attribute filename
16 17 18 |
# File 'lib/adhearsion/asterisk/config_manager.rb', line 16 def filename @filename end |
Class Method Details
+ (Object) normalize_configuration(file_contents)
8 9 10 11 12 13 |
# File 'lib/adhearsion/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
- (Object) [](section_name)
26 27 28 29 |
# File 'lib/adhearsion/asterisk/config_manager.rb', line 26 def [](section_name) result = sections.find { |(name, *rest)| section_name == name } result.last if result end |
- (Object) delete_section(section_name)
31 32 33 |
# File 'lib/adhearsion/asterisk/config_manager.rb', line 31 def delete_section(section_name) sections.reject! { |(name, *rest)| section_name == name } end |
- (Object) new_section(name, properties = {})
35 36 37 |
# File 'lib/adhearsion/asterisk/config_manager.rb', line 35 def new_section(name, properties={}) sections << [name, properties] end |
- (Object) sections
22 23 24 |
# File 'lib/adhearsion/asterisk/config_manager.rb', line 22 def sections @sections ||= read_configuration end |