Class: Modesty::RedisData

Inherits:
Datastore show all
Defined in:
lib/modesty/datastore/redis.rb

Defined Under Namespace

Classes: ExperimentData, MetricData

Instance Attribute Summary

Attributes inherited from Datastore

#store

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Datastore

#connected?

Constructor Details

#initialize(options = {}) ⇒ RedisData

Returns a new instance of RedisData.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/modesty/datastore/redis.rb', line 7

def initialize(options={})
  if options[:redis]
    @store = options[:redis]
  elsif options['mock'] || options[:mock]
    require File.join(
      Modesty::VENDOR, 'mock_redis', 'lib', 'mock_redis.rb'
    )
    @store = MockRedis.new
  else
    $:.push(File.join(Modesty::VENDOR, 'redis-rb', 'lib'))
      require 'redis'
    $:.pop

    @store = Redis.new(options)
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &blk) ⇒ Object



28
29
30
31
32
# File 'lib/modesty/datastore/redis.rb', line 28

def method_missing(name, *args, &blk)
  @store.send(name, *args, &blk)
rescue Exception => e
  raise ConnectionError, e.to_s
end

Class Method Details

.date_key(date) ⇒ Object



3
4
5
# File 'lib/modesty/datastore/redis.rb', line 3

def self.date_key(date)
  "%04d-%02d-%02d" % [date.year, date.month, date.day]
end

.keyify(*args) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/modesty/datastore/redis.rb', line 34

def self.keyify(*args)
  args.map {|a| a.to_s}.map do |a|
    (a.is_a?(Date)) ? date_key(a) : a
  end.map do |k|
    k.gsub(/[^\w\-\/]/,'_')
  end.unshift('modesty').join(':')
end

Instance Method Details

#ping!Object



24
25
26
# File 'lib/modesty/datastore/redis.rb', line 24

def ping!
  self.ping
end