Class: RedisConf

Inherits:
Object
  • Object
show all
Extended by:
InputValidator
Defined in:
lib/redis_conf.rb

Overview

Class that deals with Redis server configuration options

Constant Summary

Constants included from InputValidator

InputValidator::DECIMAL_RE, InputValidator::NON_ZERO_NUMBER_RE, InputValidator::NUMBER_RE, InputValidator::STRING_RE, InputValidator::URI_RE

Class Method Summary collapse

Methods included from InputValidator

decimal?, is?, non_zero_number?, number?, string?, uri?

Class Method Details

.optionsHash

Read and parse Redis server configuration options

Returns:

  • (Hash)

    redis server options ready for use



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/redis_conf.rb', line 12

def self.options
  options = {}
  if Settings['redis']
    options[:namespace] = Settings.redis['namespace']
    options[:url] = Settings.redis['url']
  end

  options[:namespace] ||= 'oneacct_export'
  options[:url] ||= 'redis://localhost:6379'

  fail ArgumentError, "#{options[:url]} is not a valid URL."\
    unless uri?(options[:url])

  if Settings['redis'] && Settings.redis['password']
    fail ArgumentError, 'Redis password cannot be empty'\
      if Settings.redis['password'].empty?
    options[:url].insert(options[:url].index('/') + 2, ":#{Settings.redis['password']}@")
  end

  options
end