module RRRSpec
Constants
- DEFAULT_CONFIG_FILES
Public Class Methods
convert_if_present(h, key) { |h| ... }
click to toggle source
# File lib/rrrspec/redis_models.rb, line 5 def self.convert_if_present(h, key) if h[key].present? h[key] = yield h[key] else h[key] = nil end end
Public Instance Methods
configuration()
click to toggle source
# File lib/rrrspec.rb, line 19 def configuration @configuration end
configuration=(configuration)
click to toggle source
# File lib/rrrspec.rb, line 23 def configuration=(configuration) @configuration = configuration end
configure(type=nil) { |configuration| ... }
click to toggle source
# File lib/rrrspec.rb, line 27 def configure(type=nil) if type == nil || type == configuration.type yield configuration end end
flushredis()
click to toggle source
# File lib/rrrspec.rb, line 49 def flushredis Thread.list.each do |thread| thread[:redis] = nil thread[:pid] = nil end end
hostname()
click to toggle source
# File lib/rrrspec.rb, line 60 def hostname @hostname ||= Socket.gethostname end
hostname=(hostname)
click to toggle source
# File lib/rrrspec.rb, line 64 def hostname=(hostname) @hostname = hostname end
logger()
click to toggle source
# File lib/rrrspec.rb, line 92 def logger @logger ||= Logger.new(STDERR) end
logger=(logger)
click to toggle source
# File lib/rrrspec.rb, line 96 def logger=(logger) @logger = logger end
make_key(*args)
click to toggle source
# File lib/rrrspec.rb, line 56 def make_key(*args) args.join(':') end
pacemaker(obj, time, margin)
click to toggle source
# File lib/rrrspec.rb, line 68 def pacemaker(obj, time, margin) loop do obj.heartbeat(time) sleep time - margin end end
redis()
click to toggle source
# File lib/rrrspec.rb, line 33 def redis # After the process is daemonized, the redis instance is in invalid state. # We avoid using such instance by checking the PID. if not Thread.current[:pid] or Thread.current[:pid] != Process.pid Thread.current[:redis] = nil Thread.current[:pid] = Process.pid end # It is probable that if two other threads shares one redis connection # one thread blocks the other thread. We avoid this by using separate # connections. Thread.current[:redis] ||= begin configuration.redis.dup end end
setup(configuration, config_files)
click to toggle source
# File lib/rrrspec.rb, line 83 def setup(configuration, config_files) RRRSpec.configuration = configuration files = config_files files += ENV['RRRSPEC_CONFIG_FILES'].split(':') if ENV['RRRSPEC_CONFIG_FILES'] files += DEFAULT_CONFIG_FILES if files.empty? RRRSpec.configuration.load_files(files) exit 1 unless RRRSpec.configuration.check_validity end