redis-classy 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,9 +1,9 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- gem "redis-namespace", "~> 1.0.0"
3
+ gem "redis-namespace", "~> 1.0"
4
4
 
5
5
  group :development do
6
- gem "rspec", "~> 2.6.0"
7
- gem "bundler", "~> 1.0.0"
8
- gem "jeweler", "~> 1.6.0"
6
+ gem "rspec"
7
+ gem "bundler"
8
+ gem "jeweler"
9
9
  end
data/Gemfile.lock CHANGED
@@ -1,30 +1,30 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- diff-lcs (1.1.2)
4
+ diff-lcs (1.1.3)
5
5
  git (1.2.5)
6
- jeweler (1.6.0)
7
- bundler (~> 1.0.0)
6
+ jeweler (1.6.4)
7
+ bundler (~> 1.0)
8
8
  git (>= 1.2.5)
9
9
  rake
10
- rake (0.9.0)
11
- redis (2.2.0)
12
- redis-namespace (1.0.3)
10
+ rake (0.9.2.2)
11
+ redis (2.2.2)
12
+ redis-namespace (1.1.0)
13
13
  redis (< 3.0.0)
14
- rspec (2.6.0)
15
- rspec-core (~> 2.6.0)
16
- rspec-expectations (~> 2.6.0)
17
- rspec-mocks (~> 2.6.0)
18
- rspec-core (2.6.2)
19
- rspec-expectations (2.6.0)
14
+ rspec (2.7.0)
15
+ rspec-core (~> 2.7.0)
16
+ rspec-expectations (~> 2.7.0)
17
+ rspec-mocks (~> 2.7.0)
18
+ rspec-core (2.7.1)
19
+ rspec-expectations (2.7.0)
20
20
  diff-lcs (~> 1.1.2)
21
- rspec-mocks (2.6.0)
21
+ rspec-mocks (2.7.0)
22
22
 
23
23
  PLATFORMS
24
24
  ruby
25
25
 
26
26
  DEPENDENCIES
27
- bundler (~> 1.0.0)
28
- jeweler (~> 1.6.0)
29
- redis-namespace (~> 1.0.0)
30
- rspec (~> 2.6.0)
27
+ bundler
28
+ jeweler
29
+ redis-namespace (~> 1.0)
30
+ rspec
data/README.md CHANGED
@@ -5,14 +5,16 @@ Class-style namespace prefixing for Redis.
5
5
 
6
6
  With Redis Classy, class names become the prefix part of the Redis keys.
7
7
 
8
- class Something < Redis::Classy
9
- end
10
-
11
- Something.set "foo", "bar" # equivalent of => redis.set "Something:foo", "bar"
12
- Something.get "foo" # => redis.get "Something:foo"
13
- => "bar"
8
+ ```ruby
9
+ class Something < Redis::Classy
10
+ end
14
11
 
15
- This library contains only 33 lines of code, yet powerful when you need better abstraction on Redis objects to keep things organized.
12
+ Something.set 'foo', 'bar' # equivalent of => redis.set 'Something:foo', 'bar'
13
+ Something.get 'foo' # => redis.get 'Something:foo'
14
+ => "bar"
15
+ ```
16
+
17
+ This library contains only 30+ lines of code, yet powerful when you need better abstraction on Redis objects to keep things organized.
16
18
 
17
19
  Requies the `redis-namespace` gem.
18
20
 
@@ -23,24 +25,30 @@ What's new:
23
25
  Synopsis
24
26
  --------
25
27
 
26
- With the vanilla redis gem, you've been doing this:
28
+ With the vanilla `redis` gem, you've been doing this:
27
29
 
28
- redis = Redis.new
29
- redis.set "foo", "bar"
30
+ ```ruby
31
+ redis = Redis.new
32
+ redis.set 'foo', 'bar'
33
+ ```
30
34
 
31
- With the redis-namespace gem, you can add a prefix in the following manner:
35
+ With the `redis-namespace` gem, you can add a prefix in the following manner:
32
36
 
33
- redis_ns = Redis::Namespace.new('ns', :redis => redis)
34
- redis_ns['foo'] = 'bar' # equivalent of => redis.set "ns:foo", "bar"
37
+ ```ruby
38
+ redis_ns = Redis::Namespace.new('ns', :redis => redis)
39
+ redis_ns['foo'] = 'bar' # equivalent of => redis.set 'ns:foo', 'bar'
40
+ ```
35
41
 
36
42
  Now, with the redis-classy gem, you could finally do:
37
43
 
38
- class Something < Redis::Classy
39
- end
40
-
41
- Something.set "foo", "bar" # equivalent of => redis.set "Prefix:foo", "bar"
42
- Something.get "foo"
43
- => "bar"
44
+ ```ruby
45
+ class Something < Redis::Classy
46
+ end
47
+
48
+ Something.set 'foo', 'bar' # equivalent of => redis.set 'Prefix:foo', 'bar'
49
+ Something.get 'foo'
50
+ => "bar"
51
+ ```
44
52
 
45
53
  Install
46
54
  -------
@@ -52,69 +60,81 @@ Usage
52
60
 
53
61
  In Gemfile:
54
62
 
55
- gem "redis-classy"
63
+ ```ruby
64
+ gem 'redis-classy'
65
+ ```
56
66
 
57
67
  In config/initializers/redis_classy.rb:
58
68
 
59
- Redis::Classy.db = Redis.new
69
+ ```ruby
70
+ Redis::Classy.db = Redis.new
71
+ ```
60
72
 
61
73
  Now you can write models that inherit the Redis::Classy class, automatically prefixing keys with its class name.
62
74
  You can use any Redis commands on the class, since they are simply passed to the Redis instance.
63
75
 
64
- class UniqueUser < Redis::Classy
65
- def self.nuke
66
- self.keys.each{|key| self.del(key) }
67
- end
68
- end
69
-
70
- UniqueUser.sadd "2011-02-28", @user_a.id
71
- UniqueUser.sadd "2011-02-28", @user_b.id
72
- UniqueUser.sadd "2011-03-01", @user_c.id
73
-
74
- UniqueUser.smembers "2011-02-28"
75
- => ["123", "456"]
76
-
77
- UniqueUser.nuke
78
- => ["2011-02-28", "2011-03-01"]
79
-
80
- UniqueUser.keys
81
- => []
76
+ ```ruby
77
+ class UniqueUser < Redis::Classy
78
+ def self.nuke
79
+ self.keys.each{|key| self.del(key) }
80
+ end
81
+ end
82
+
83
+ UniqueUser.sadd '2011-02-28', @user_a.id
84
+ UniqueUser.sadd '2011-02-28', @user_b.id
85
+ UniqueUser.sadd '2011-03-01', @user_c.id
86
+
87
+ UniqueUser.smembers '2011-02-28'
88
+ => ["123", "456"]
89
+
90
+ UniqueUser.nuke
91
+ => ["2011-02-28", "2011-03-01"]
92
+
93
+ UniqueUser.keys
94
+ => []
95
+ ```
82
96
 
83
97
  In most cases you may be just fine with class methods, but by creating an instance with a key, even further binding is possible.
84
98
 
85
- class Counter < Redis::Classy
86
- def initialize(object)
87
- super("#{object.class.name}:#{object.id}")
88
- end
89
- end
90
-
91
- class Room < ActiveRecord::Base
92
- end
93
-
94
- @room = Room.create
95
-
96
- counter = Counter.new(@room)
97
- counter.incr
98
- counter.incr
99
- counter.get
100
- => "2"
101
-
102
- counter.key
103
- => "Room:123"
99
+ ```ruby
100
+ class Counter < Redis::Classy
101
+ def initialize(object)
102
+ super("#{object.class.name}:#{object.id}")
103
+ end
104
+ end
105
+
106
+ class Room < ActiveRecord::Base
107
+ end
108
+
109
+ @room = Room.create
110
+
111
+ counter = Counter.new(@room)
112
+ counter.incr
113
+ counter.incr
114
+ counter.get
115
+ => "2"
116
+
117
+ counter.key
118
+ => "Room:123"
119
+ ```
104
120
 
105
121
  You also have access to the non-namespaced, raw Redis instance via Redis::Classy
106
122
 
107
- Redis::Classy.keys "UniqueUser:*"
108
- => ["UniqueUser:2011-02-28", "UniqueUser:2011-03-01"]
109
-
110
- Redis::Classy.multi do
111
- UniqueUser.sadd "2011-02-28", @user_a.id
112
- UniqueUser.sadd "2011-02-28", @user_b.id
113
- end
123
+ ```ruby
124
+ Redis::Classy.keys 'UniqueUser:*'
125
+ => ["UniqueUser:2011-02-28", "UniqueUser:2011-03-01"]
126
+
127
+ Redis::Classy.multi do
128
+ UniqueUser.sadd '2011-02-28', @user_a.id
129
+ UniqueUser.sadd '2011-02-28', @user_b.id
130
+ end
131
+ ```
114
132
 
115
- Since the "db" attribute is a class instance variable, you can dynamically assign different databases for each class.
133
+ Since the `db` attribute is a class instance variable, you can dynamically assign different databases for each class.
116
134
 
117
- UniqueUser.db = Redis::Namespace.new("UniqueUser", :redis => Redis.new(:host => "another.host"))
135
+ ```ruby
136
+ UniqueUser.db = Redis::Namespace.new('UniqueUser', :redis => Redis.new(:host => 'another.host'))
137
+ ```
118
138
 
119
139
  Reference
120
140
  ---------
data/Rakefile CHANGED
@@ -24,5 +24,5 @@ Jeweler::RubygemsDotOrgTasks.new
24
24
 
25
25
  task :default => :spec
26
26
  task :spec do
27
- exec "rspec spec/redis-classy_spec.rb"
27
+ exec "rspec spec"
28
28
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.0.1
data/lib/redis-classy.rb CHANGED
@@ -1 +1,5 @@
1
- require File.dirname(__FILE__) + '/redis/classy'
1
+ require 'redis-namespace'
2
+
3
+ class Redis
4
+ autoload :Classy, 'redis/classy'
5
+ end
data/lib/redis/classy.rb CHANGED
@@ -1,5 +1,3 @@
1
- require 'redis-namespace'
2
-
3
1
  class Redis
4
2
  class Classy
5
3
  class << self
data/redis-classy.gemspec CHANGED
@@ -4,14 +4,14 @@
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = %q{redis-classy}
8
- s.version = "1.0.0"
7
+ s.name = "redis-classy"
8
+ s.version = "1.0.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kenn Ejima"]
12
- s.date = %q{2011-05-21}
13
- s.description = %q{Class-style namespace prefixing for Redis}
14
- s.email = %q{kenn.ejima@gmail.com}
12
+ s.date = "2011-11-05"
13
+ s.description = "Class-style namespace prefixing for Redis"
14
+ s.email = "kenn.ejima@gmail.com"
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE.txt",
17
17
  "README.md"
@@ -28,34 +28,34 @@ Gem::Specification.new do |s|
28
28
  "lib/redis-classy.rb",
29
29
  "lib/redis/classy.rb",
30
30
  "redis-classy.gemspec",
31
- "spec/redis-classy_spec.rb",
31
+ "spec/redis_classy_spec.rb",
32
32
  "spec/spec_helper.rb"
33
33
  ]
34
- s.homepage = %q{http://github.com/kenn/redis-classy}
34
+ s.homepage = "http://github.com/kenn/redis-classy"
35
35
  s.licenses = ["MIT"]
36
36
  s.require_paths = ["lib"]
37
- s.rubygems_version = %q{1.6.2}
38
- s.summary = %q{Class-style namespace prefixing for Redis}
37
+ s.rubygems_version = "1.8.11"
38
+ s.summary = "Class-style namespace prefixing for Redis"
39
39
 
40
40
  if s.respond_to? :specification_version then
41
41
  s.specification_version = 3
42
42
 
43
43
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
44
- s.add_runtime_dependency(%q<redis-namespace>, ["~> 1.0.0"])
45
- s.add_development_dependency(%q<rspec>, ["~> 2.6.0"])
46
- s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
47
- s.add_development_dependency(%q<jeweler>, ["~> 1.6.0"])
44
+ s.add_runtime_dependency(%q<redis-namespace>, ["~> 1.0"])
45
+ s.add_development_dependency(%q<rspec>, [">= 0"])
46
+ s.add_development_dependency(%q<bundler>, [">= 0"])
47
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
48
48
  else
49
- s.add_dependency(%q<redis-namespace>, ["~> 1.0.0"])
50
- s.add_dependency(%q<rspec>, ["~> 2.6.0"])
51
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
52
- s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
49
+ s.add_dependency(%q<redis-namespace>, ["~> 1.0"])
50
+ s.add_dependency(%q<rspec>, [">= 0"])
51
+ s.add_dependency(%q<bundler>, [">= 0"])
52
+ s.add_dependency(%q<jeweler>, [">= 0"])
53
53
  end
54
54
  else
55
- s.add_dependency(%q<redis-namespace>, ["~> 1.0.0"])
56
- s.add_dependency(%q<rspec>, ["~> 2.6.0"])
57
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
58
- s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
55
+ s.add_dependency(%q<redis-namespace>, ["~> 1.0"])
56
+ s.add_dependency(%q<rspec>, [">= 0"])
57
+ s.add_dependency(%q<bundler>, [">= 0"])
58
+ s.add_dependency(%q<jeweler>, [">= 0"])
59
59
  end
60
60
  end
61
61
 
@@ -7,45 +7,48 @@ describe "RedisClassy" do
7
7
  before(:each) do
8
8
  Redis::Classy.flushdb
9
9
  end
10
-
10
+
11
11
  after(:each) do
12
12
  Redis::Classy.flushdb
13
13
  end
14
-
14
+
15
15
  after(:all) do
16
16
  Redis::Classy.quit
17
17
  end
18
-
18
+
19
19
  it "should prepend class name to the key" do
20
20
  Something.set("foo", "bar")
21
-
21
+
22
22
  Something.keys.should == ["foo"]
23
23
  Redis::Classy.keys.should == ["Something:foo"]
24
24
  end
25
-
25
+
26
26
  it "should delegate class methods" do
27
27
  Something.get("foo").should == nil
28
28
  Something.set("foo", "bar")
29
29
  Something.get("foo").should == "bar"
30
30
  end
31
-
31
+
32
32
  it "should delegate instance methods with the key binding" do
33
33
  something = Something.new("foo")
34
-
34
+
35
35
  something.get.should == nil
36
36
  something.set("bar")
37
37
  something.get.should == "bar"
38
38
  end
39
-
39
+
40
40
  it "should handle multi block" do
41
+ something = Something.new("foo")
42
+
41
43
  Redis::Classy.multi do
42
- Something.sadd "foo", "bar"
43
- Something.sadd "foo", "baz"
44
+ something.sadd 1
45
+ something.sadd 2
46
+ something.sadd 3
44
47
  end
45
-
46
- Something.smembers("foo").should == ["baz", "bar"]
48
+
49
+ something.smembers.should == ['1','2','3']
47
50
  end
48
-
51
+
49
52
  it "should battle against mongoid" do
50
53
  # Emulate notorious Mongoid::Extensions::Object::Conversions
51
54
  class Object
@@ -53,11 +56,11 @@ describe "RedisClassy" do
53
56
  value
54
57
  end
55
58
  end
56
-
59
+
57
60
  # This would have returned "foo" instead of nil, unless we explicitly defined
58
61
  # class methods from Redis::Namespace::COMMANDS
59
62
  Something.get("foo").should == nil
60
-
63
+
61
64
  class << Object
62
65
  remove_method :get
63
66
  end
metadata CHANGED
@@ -1,72 +1,68 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: redis-classy
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
4
5
  prerelease:
5
- version: 1.0.0
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Kenn Ejima
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-05-21 00:00:00 -07:00
14
- default_executable:
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
12
+ date: 2011-11-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
17
15
  name: redis-namespace
18
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &70246658294580 !ruby/object:Gem::Requirement
19
17
  none: false
20
- requirements:
18
+ requirements:
21
19
  - - ~>
22
- - !ruby/object:Gem::Version
23
- version: 1.0.0
20
+ - !ruby/object:Gem::Version
21
+ version: '1.0'
24
22
  type: :runtime
25
23
  prerelease: false
26
- version_requirements: *id001
27
- - !ruby/object:Gem::Dependency
24
+ version_requirements: *70246658294580
25
+ - !ruby/object:Gem::Dependency
28
26
  name: rspec
29
- requirement: &id002 !ruby/object:Gem::Requirement
27
+ requirement: &70246658294100 !ruby/object:Gem::Requirement
30
28
  none: false
31
- requirements:
32
- - - ~>
33
- - !ruby/object:Gem::Version
34
- version: 2.6.0
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
35
33
  type: :development
36
34
  prerelease: false
37
- version_requirements: *id002
38
- - !ruby/object:Gem::Dependency
35
+ version_requirements: *70246658294100
36
+ - !ruby/object:Gem::Dependency
39
37
  name: bundler
40
- requirement: &id003 !ruby/object:Gem::Requirement
38
+ requirement: &70246658293560 !ruby/object:Gem::Requirement
41
39
  none: false
42
- requirements:
43
- - - ~>
44
- - !ruby/object:Gem::Version
45
- version: 1.0.0
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
46
44
  type: :development
47
45
  prerelease: false
48
- version_requirements: *id003
49
- - !ruby/object:Gem::Dependency
46
+ version_requirements: *70246658293560
47
+ - !ruby/object:Gem::Dependency
50
48
  name: jeweler
51
- requirement: &id004 !ruby/object:Gem::Requirement
49
+ requirement: &70246658293060 !ruby/object:Gem::Requirement
52
50
  none: false
53
- requirements:
54
- - - ~>
55
- - !ruby/object:Gem::Version
56
- version: 1.6.0
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
57
55
  type: :development
58
56
  prerelease: false
59
- version_requirements: *id004
57
+ version_requirements: *70246658293060
60
58
  description: Class-style namespace prefixing for Redis
61
59
  email: kenn.ejima@gmail.com
62
60
  executables: []
63
-
64
61
  extensions: []
65
-
66
- extra_rdoc_files:
62
+ extra_rdoc_files:
67
63
  - LICENSE.txt
68
64
  - README.md
69
- files:
65
+ files:
70
66
  - .document
71
67
  - .rspec
72
68
  - Gemfile
@@ -78,38 +74,34 @@ files:
78
74
  - lib/redis-classy.rb
79
75
  - lib/redis/classy.rb
80
76
  - redis-classy.gemspec
81
- - spec/redis-classy_spec.rb
77
+ - spec/redis_classy_spec.rb
82
78
  - spec/spec_helper.rb
83
- has_rdoc: true
84
79
  homepage: http://github.com/kenn/redis-classy
85
- licenses:
80
+ licenses:
86
81
  - MIT
87
82
  post_install_message:
88
83
  rdoc_options: []
89
-
90
- require_paths:
84
+ require_paths:
91
85
  - lib
92
- required_ruby_version: !ruby/object:Gem::Requirement
86
+ required_ruby_version: !ruby/object:Gem::Requirement
93
87
  none: false
94
- requirements:
95
- - - ">="
96
- - !ruby/object:Gem::Version
97
- hash: 1700316394967053203
98
- segments:
88
+ requirements:
89
+ - - ! '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ segments:
99
93
  - 0
100
- version: "0"
101
- required_rubygems_version: !ruby/object:Gem::Requirement
94
+ hash: -3343369064691227206
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
96
  none: false
103
- requirements:
104
- - - ">="
105
- - !ruby/object:Gem::Version
106
- version: "0"
97
+ requirements:
98
+ - - ! '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
107
101
  requirements: []
108
-
109
102
  rubyforge_project:
110
- rubygems_version: 1.6.2
103
+ rubygems_version: 1.8.11
111
104
  signing_key:
112
105
  specification_version: 3
113
106
  summary: Class-style namespace prefixing for Redis
114
107
  test_files: []
115
-