Class: Redis::Config
- Inherits:
-
Hash
- Object
- Hash
- Redis::Config
- Defined in:
- lib/redis/config.rb
Constant Summary collapse
- INTEGERS =
[:port, :timeout, :databases]
- BOOLEANS =
[:daemonize]
Instance Method Summary collapse
-
#initialize(argf_or_hash) ⇒ Config
constructor
A new instance of Config.
Constructor Details
#initialize(argf_or_hash) ⇒ Config
Returns a new instance of Config.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/redis/config.rb', line 7 def initialize argf_or_hash # defaults self[:dir] = '.' self[:logfile] = 'stdout' self[:loglevel] = 'verbose' self[:daemonize] = false self[:pidfile] = '/var/run/redis.pid' self[:bind] = '127.0.0.1' self[:port] = 6379 self[:timeout] = 300 self[:databases] = 16 this = super() if Hash === argf_or_hash super argf_or_hash else super() # load from ARGF or IO compatible interface argf_or_hash.each do |line| key, val = line.split ' ', 2 self[key.downcase.gsub(/-/,'_').to_sym] = val.chomp "\n" end end # convert INTEGERS.each do |key| this[key] = this[key].to_i end # convert BOOLEANS.each do |key| next unless String===this[key] this[key] = case this[key].downcase when 'yes' then true when 'no' then false else nil end end end |