Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a794a83
commit 06bf235
Showing
8 changed files
with
103 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
module Translator | ||
class RedisStore | ||
def initialize(redis) | ||
@redis = redis | ||
end | ||
|
||
def keys | ||
@redis.keys | ||
end | ||
|
||
def []=(key, value) | ||
value = nil if value.blank? | ||
@redis[key] = ActiveSupport::JSON.encode(value) | ||
end | ||
|
||
def [](key) | ||
@redis[key] | ||
end | ||
|
||
def clear_database | ||
@redis.keys.clone.each {|key| @redis.del key } | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# encoding: UTF-8 | ||
require 'spec_helper' | ||
|
||
describe Translator::RedisStore do | ||
before :each do | ||
@store = Translator::RedisStore.new(Redis.new) | ||
@store.clear_database | ||
end | ||
|
||
it "should be possible to set translation value" do | ||
@store["pl.hello.world"] = "Witaj, świecie!" | ||
@store["pl.hello.world"].should eql("\"Witaj, \\u015bwiecie!\"") | ||
end | ||
|
||
it "should list all keys" do | ||
@store["pl.hello.world"] = "Witaj, świecie!" | ||
@store["en.hello.world"] = "Hello, World!" | ||
@store.keys.should include("pl.hello.world") | ||
@store.keys.should include("en.hello.world") | ||
end | ||
end |