Sha256: 9f72c5eaba90f480b7825fb896fbe940812fd26f03c3e542f3b601bac42303d1
Contents?: true
Size: 1.05 KB
Versions: 7
Compression:
Stored size: 1.05 KB
Contents
class MockRedis module UtilityMethods private def with_thing_at(key, assertion, empty_thing_generator) send(assertion, key) data[key] ||= empty_thing_generator.call data_key_ref = data[key] ret = yield data[key] data[key] = data_key_ref if data[key].nil? primitive?(ret) ? ret.dup : ret ensure clean_up_empties_at(key) end def primitive?(value) value.is_a?(::Array) || value.is_a?(::Hash) || value.is_a?(::String) end def clean_up_empties_at(key) if data[key] && data[key].empty? del(key) end end def common_scan(values, cursor, opts = {}) count = (opts[:count] || 10).to_i cursor = cursor.to_i match = opts[:match] || '*' key = opts[:key] || lambda { |x| x } limit = cursor + count next_cursor = limit >= values.length ? '0' : limit.to_s filtered_values = values[cursor...limit].select do |val| redis_pattern_to_ruby_regex(match).match(key.call(val)) end [next_cursor, filtered_values] end end end
Version data entries
7 entries across 7 versions & 1 rubygems