Class: SimpleFeed::Providers::Redis::Driver::LoggingRedis

Inherits:
Struct
  • Object
show all
Defined in:
lib/simplefeed/providers/redis/driver.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/simplefeed/providers/redis/driver.rb', line 43

def method_missing(m, *args, &block)
  if redis.respond_to?(m)
    t1         = Time.now
    result     = redis.send(m, *args, &block)
    delta      = Time.now - t1
    colors     = [:blue, nil, :blue, :blue, :yellow, :cyan, nil, :blue]
    components = [
      Time.now.strftime('%H:%M:%S.%L'), ' rtt=',
      (sprintf '%.5f', delta*1000), ' ms ',
      (sprintf '%15s ', m.to_s.upcase),
      (sprintf '%-40s', args.inspect.gsub(/[",\[\]]/, '')), '',
      (result.is_a?(::Redis::Future) ? '' : result.to_s)]
    components.each_with_index do |component, index|
      color = self.class.disable_color ? nil : colors[index]
      component = component.send(color) if color
      self.class.stream.printf component
    end
    self.class.stream.puts
    result
  else
    super
  end
end

Class Attribute Details

.disable_colorObject

in case someone might prefer to dump it into STDOUT instead, just set SimpleFeed::Providers::Redis::Driver::LoggingRedis.stream = STDOUT | STDERR | etc…



40
41
42
# File 'lib/simplefeed/providers/redis/driver.rb', line 40

def disable_color
  @disable_color
end

.streamObject

in case someone might prefer to dump it into STDOUT instead, just set SimpleFeed::Providers::Redis::Driver::LoggingRedis.stream = STDOUT | STDERR | etc…



40
41
42
# File 'lib/simplefeed/providers/redis/driver.rb', line 40

def stream
  @stream
end

Instance Attribute Details

#redisObject

Returns the value of attribute redis

Returns:

  • (Object)

    the current value of redis



34
35
36
# File 'lib/simplefeed/providers/redis/driver.rb', line 34

def redis
  @redis
end