Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: redis-store/redis-store
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: mikeabiezzi/redis-store
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 1 commit
  • 2 files changed
  • 1 contributor

Commits on Jan 18, 2013

  1. Copy the full SHA
    142b94f View commit details
Showing with 16 additions and 2 deletions.
  1. +10 −2 redis-store/lib/redis/store/namespace.rb
  2. +6 −0 redis-store/test/redis/store/namespace_test.rb
12 changes: 10 additions & 2 deletions redis-store/lib/redis/store/namespace.rb
Original file line number Diff line number Diff line change
@@ -51,15 +51,23 @@ def namespace(key)
end

def interpolate(key)
key.match(namespace_regexp) ? key : "#{@namespace}:#{key}"
key.match(namespace_regexp) ? key : "#{prefix}:#{key}"
end

def prefix
@namespace.is_a?(Proc) ? @namespace.call : @namespace
end

def strip_namespace(key)
key.gsub namespace_regexp, ""
end

def namespace_regexp
@namespace_regexp ||= %r{^#{@namespace}\:}
if @namespace.is_a?(Proc)
%r{^#{prefix}\:}
else
@namespace_regexp ||= %r{^#{@namespace}\:}
end
end
end
end
6 changes: 6 additions & 0 deletions redis-store/test/redis/store/namespace_test.rb
Original file line number Diff line number Diff line change
@@ -23,6 +23,12 @@ def teardown
@store.send(:interpolate, "#{@namespace}:rabbit").must_equal("#{@namespace}:rabbit")
end

it "dynamically namespaces when the namespace is a lambda" do
namespace = lambda { "dynamic" }
store = Redis::Store.new :namespace => namespace
store.send(:interpolate, "rabbit").must_equal("dynamic:rabbit")
end

it "should only delete namespaced keys" do
other_store = Redis::Store.new