Class: Freeswitch::ESL::Configuration

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/freeswitch/esl/configuration.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



39
40
41
# File 'lib/freeswitch/esl/configuration.rb', line 39

def initialize(**)
  @config = self.class.build(**)
end

Class Method Details

.build(**options) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/freeswitch/esl/configuration.rb', line 27

def build(**options)
  config = Configatron::RootStore.new
  config.freeswitch.configure_from_hash(defaults[:freeswitch].dup.merge(options[:freeswitch] || {}))
  config.logger = options[:logger] || defaults[:logger]
  config.debug = options[:debug] || defaults[:debug]
  config
end

.defaultsObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/freeswitch/esl/configuration.rb', line 12

def defaults
  @defaults ||= {
    freeswitch: {
      host: ENV.fetch("FREESWITCH_ESL_HOST", "127.0.0.1"),
      port: ENV.fetch("FREESWITCH_ESL_PORT", 8021).to_i,
      password: ENV.fetch("FREESWITCH_ESL_PASSWORD", nil),
      reconnect: %w[true 1 yes].include?(ENV.fetch("FREESWITCH_ESL_RECONNECT", "true").downcase),
      retry_delay: ENV.fetch("FREESWITCH_ESL_RETRY_DELAY", 1.0).to_f,
      max_retries: Float::INFINITY
    },
    logger: Freeswitch::ESL::Logger.default_logger,
    debug: false
  }.freeze
end

Instance Method Details

#update(**options) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/freeswitch/esl/configuration.rb', line 43

def update(**options)
  %i[freeswitch logger debug].each do |key|
    next unless options.key?(key)

    if key == :freeswitch
      @config.freeswitch.configure_from_hash(options[:freeswitch])
    else
      @config[key] = options[key] || @config[key]
    end
  end
end