redis-aid 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +11 -0
- data/LICENSE +20 -0
- data/README.rdoc +59 -0
- data/Rakefile +46 -0
- data/lib/redis-aid.rb +50 -0
- data/redis-aid.gemspec +22 -0
- data/spec/redis_aid_spec.rb +88 -0
- data/spec/spec_helper.rb +7 -0
- metadata +134 -0
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Kriss 'nu7hatch' Kowalik
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
= Redis Aid
|
2
|
+
|
3
|
+
Small lib which helps with extending your classes or modules with redis (and nest) goodies.
|
4
|
+
|
5
|
+
== Installation
|
6
|
+
|
7
|
+
From rubygems:
|
8
|
+
|
9
|
+
gem install redis-aid # with sudo if necessary
|
10
|
+
|
11
|
+
== Examples
|
12
|
+
|
13
|
+
You can configure global redis connection:
|
14
|
+
|
15
|
+
Redis::Aid.redis = Redis.new
|
16
|
+
|
17
|
+
Simple usage:
|
18
|
+
|
19
|
+
class MyClass
|
20
|
+
include Redis::Aid
|
21
|
+
|
22
|
+
def foo
|
23
|
+
redis.get(:foo)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
Powered by nest:
|
28
|
+
|
29
|
+
class MySecondClass
|
30
|
+
include Redis::Aid::Ns(:foo)
|
31
|
+
|
32
|
+
def bar
|
33
|
+
redis[:bar].get # => value of 'foo:bar'
|
34
|
+
end
|
35
|
+
|
36
|
+
def spam_and_eggs
|
37
|
+
redis[:spam][:eggs].get # => value of 'foo:spam:eggs'
|
38
|
+
end
|
39
|
+
|
40
|
+
Custom redis connection for each class? No problem:
|
41
|
+
|
42
|
+
class MyThirdClass
|
43
|
+
include Redis::Aid
|
44
|
+
redis = Redis.connect(:host => "host.com")
|
45
|
+
end
|
46
|
+
|
47
|
+
== Note on Patches/Pull Requests
|
48
|
+
|
49
|
+
* Fork the project.
|
50
|
+
* Make your feature addition or bug fix.
|
51
|
+
* Add tests for it. This is important so I don't break it in a
|
52
|
+
future version unintentionally.
|
53
|
+
* Commit, do not mess with rakefile, version, or history.
|
54
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
55
|
+
* Send me a pull request. Bonus points for topic branches.
|
56
|
+
|
57
|
+
== Copyright
|
58
|
+
|
59
|
+
Copyright (c) 2010 Kriss 'nu7hatch' Kowalik. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
$:.unshift(File.expand_path('../lib', __FILE__))
|
3
|
+
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
require 'rake/rdoctask'
|
6
|
+
require 'redis-aid'
|
7
|
+
|
8
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
9
|
+
t.pattern = 'spec/**/*_spec.rb'
|
10
|
+
t.rspec_opts = %q[-c -b]
|
11
|
+
end
|
12
|
+
|
13
|
+
RSpec::Core::RakeTask.new(:rcov) do |t|
|
14
|
+
t.rcov = true
|
15
|
+
t.rspec_opts = %q[-c -b]
|
16
|
+
t.rcov_opts = %q[-T -x "spec"]
|
17
|
+
end
|
18
|
+
|
19
|
+
Rake::RDocTask.new do |rdoc|
|
20
|
+
rdoc.rdoc_dir = 'rdoc'
|
21
|
+
rdoc.title = "Redis Aid #{Redis::Aid.version}"
|
22
|
+
rdoc.rdoc_files.include('README*')
|
23
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
24
|
+
end
|
25
|
+
|
26
|
+
task :default => :spec
|
27
|
+
|
28
|
+
desc "Build current version as a rubygem"
|
29
|
+
task :build do
|
30
|
+
`gem build redis-aid.gemspec`
|
31
|
+
`mkdir -p pkg`
|
32
|
+
`mv redis-aid-*.gem pkg/`
|
33
|
+
end
|
34
|
+
|
35
|
+
desc "Relase current version to rubygems.org"
|
36
|
+
task :release => :build do
|
37
|
+
`git tag -am "Version bump to #{Redis::Aid.version}" v#{Redis::Aid.version}`
|
38
|
+
`git push origin master`
|
39
|
+
`git push origin master --tags`
|
40
|
+
`gem push pkg/redis-aid-#{Redis::Aid.version}.gem`
|
41
|
+
end
|
42
|
+
|
43
|
+
desc "Perform installation via rubygems"
|
44
|
+
task :install => :build do
|
45
|
+
`gem install pkg/redis-aid-#{Redis::Aid.version}.gem`
|
46
|
+
end
|
data/lib/redis-aid.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require "redis"
|
2
|
+
require "nest"
|
3
|
+
|
4
|
+
class Redis
|
5
|
+
module Aid
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def version
|
9
|
+
"0.0.1"
|
10
|
+
end
|
11
|
+
|
12
|
+
attr_accessor :redis
|
13
|
+
|
14
|
+
def redis
|
15
|
+
@redis ||= Redis.new
|
16
|
+
end
|
17
|
+
|
18
|
+
def Namespace(ns)
|
19
|
+
Redis::Aid.instance_variable_set("@ns", ns)
|
20
|
+
Redis::Aid
|
21
|
+
end
|
22
|
+
alias :Ns :Namespace
|
23
|
+
end # << self
|
24
|
+
|
25
|
+
module ClassMethods
|
26
|
+
attr_accessor :redis
|
27
|
+
|
28
|
+
def redis
|
29
|
+
@redis ||= Redis::Aid.redis
|
30
|
+
end
|
31
|
+
|
32
|
+
def ns=(namespace)
|
33
|
+
@redis = Nest.new(namespace, redis)
|
34
|
+
end
|
35
|
+
end # ClassMethods
|
36
|
+
|
37
|
+
module InstanceMethods
|
38
|
+
def redis
|
39
|
+
self.class.redis
|
40
|
+
end
|
41
|
+
end # InstanceMethods
|
42
|
+
|
43
|
+
def self.included(base) # :nodoc:
|
44
|
+
base.send :extend, ClassMethods
|
45
|
+
base.send :include, InstanceMethods
|
46
|
+
base.ns = @ns and @ns = nil if @ns
|
47
|
+
end
|
48
|
+
|
49
|
+
end # Aid
|
50
|
+
end # Redis
|
data/redis-aid.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
$:.unshift(File.expand_path('../lib', __FILE__))
|
3
|
+
require 'redis-aid'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'redis-aid'
|
7
|
+
s.version = Redis::Aid.version
|
8
|
+
s.homepage = 'http://github.com/nu7hatch/redis-aid'
|
9
|
+
s.email = ['chris@nu7hat.ch']
|
10
|
+
s.authors = ['Chris Kowalik']
|
11
|
+
s.summary = %q{The Redis first aid!}
|
12
|
+
s.description = %q{Small lib which helps with extending your classes or modules with redis (and nest) goodies.}
|
13
|
+
s.files = `git ls-files`.split("\n")
|
14
|
+
s.test_files = `git ls-files -- {spec}/*`.split("\n")
|
15
|
+
s.require_paths = %w[lib]
|
16
|
+
s.extra_rdoc_files = %w[LICENSE README.rdoc]
|
17
|
+
|
18
|
+
s.add_runtime_dependency 'redis', [">= 2.0"]
|
19
|
+
s.add_runtime_dependency 'nest', [">= 0"]
|
20
|
+
s.add_development_dependency 'rspec', ["~> 2.0"]
|
21
|
+
s.add_development_dependency 'mocha', [">= 0.9"]
|
22
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require File.expand_path("../spec_helper", __FILE__)
|
2
|
+
|
3
|
+
class First
|
4
|
+
include Redis::Aid
|
5
|
+
end
|
6
|
+
|
7
|
+
class Second
|
8
|
+
include Redis::Aid::Ns(:test)
|
9
|
+
end
|
10
|
+
|
11
|
+
describe Redis::Aid do
|
12
|
+
subject do
|
13
|
+
Redis::Aid
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#redis" do
|
17
|
+
context "when no connection set before" do
|
18
|
+
it "should return default connection" do
|
19
|
+
Redis::Aid.redis.should be_kind_of Redis
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "when connection set before" do
|
24
|
+
it "should return it" do
|
25
|
+
Redis::Aid.redis = "test"
|
26
|
+
Redis::Aid.redis.should == "test"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "Class with Redis Aid" do
|
33
|
+
subject do
|
34
|
+
First
|
35
|
+
end
|
36
|
+
|
37
|
+
before do
|
38
|
+
Redis::Aid.redis = "test"
|
39
|
+
end
|
40
|
+
|
41
|
+
describe ".redis" do
|
42
|
+
context "when no custom connection set before" do
|
43
|
+
it "should return global connection" do
|
44
|
+
klass = subject
|
45
|
+
klass.redis.should == "test"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context "when custom connection set" do
|
50
|
+
it "should return it" do
|
51
|
+
klass = subject
|
52
|
+
klass.redis = "test2"
|
53
|
+
klass.redis.should == "test2"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "#redis" do
|
59
|
+
it "should be alias for .redis" do
|
60
|
+
klass = subject.new
|
61
|
+
klass.class.redis = "testing"
|
62
|
+
klass.redis.should == "testing"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "Class with namespaced Redis Aid" do
|
68
|
+
subject do
|
69
|
+
Second
|
70
|
+
end
|
71
|
+
|
72
|
+
before do
|
73
|
+
Redis::Aid.redis = Redis.new
|
74
|
+
end
|
75
|
+
|
76
|
+
describe "#redis" do
|
77
|
+
it "should return nested client instance" do
|
78
|
+
klass = subject
|
79
|
+
klass.redis.should be_kind_of Nest
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should work properly" do
|
83
|
+
Redis::Aid.redis.set("test:bar:bla", "testing")
|
84
|
+
klass = subject
|
85
|
+
klass.redis[:bar][:bla].get.should == "testing"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: redis-aid
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Chris Kowalik
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-11-17 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: redis
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 2
|
32
|
+
- 0
|
33
|
+
version: "2.0"
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: nest
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 3
|
45
|
+
segments:
|
46
|
+
- 0
|
47
|
+
version: "0"
|
48
|
+
type: :runtime
|
49
|
+
version_requirements: *id002
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: rspec
|
52
|
+
prerelease: false
|
53
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ~>
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
hash: 3
|
59
|
+
segments:
|
60
|
+
- 2
|
61
|
+
- 0
|
62
|
+
version: "2.0"
|
63
|
+
type: :development
|
64
|
+
version_requirements: *id003
|
65
|
+
- !ruby/object:Gem::Dependency
|
66
|
+
name: mocha
|
67
|
+
prerelease: false
|
68
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
hash: 25
|
74
|
+
segments:
|
75
|
+
- 0
|
76
|
+
- 9
|
77
|
+
version: "0.9"
|
78
|
+
type: :development
|
79
|
+
version_requirements: *id004
|
80
|
+
description: Small lib which helps with extending your classes or modules with redis (and nest) goodies.
|
81
|
+
email:
|
82
|
+
- chris@nu7hat.ch
|
83
|
+
executables: []
|
84
|
+
|
85
|
+
extensions: []
|
86
|
+
|
87
|
+
extra_rdoc_files:
|
88
|
+
- LICENSE
|
89
|
+
- README.rdoc
|
90
|
+
files:
|
91
|
+
- .gitignore
|
92
|
+
- LICENSE
|
93
|
+
- README.rdoc
|
94
|
+
- Rakefile
|
95
|
+
- lib/redis-aid.rb
|
96
|
+
- redis-aid.gemspec
|
97
|
+
- spec/redis_aid_spec.rb
|
98
|
+
- spec/spec_helper.rb
|
99
|
+
has_rdoc: true
|
100
|
+
homepage: http://github.com/nu7hatch/redis-aid
|
101
|
+
licenses: []
|
102
|
+
|
103
|
+
post_install_message:
|
104
|
+
rdoc_options: []
|
105
|
+
|
106
|
+
require_paths:
|
107
|
+
- lib
|
108
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
109
|
+
none: false
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
hash: 3
|
114
|
+
segments:
|
115
|
+
- 0
|
116
|
+
version: "0"
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
none: false
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
hash: 3
|
123
|
+
segments:
|
124
|
+
- 0
|
125
|
+
version: "0"
|
126
|
+
requirements: []
|
127
|
+
|
128
|
+
rubyforge_project:
|
129
|
+
rubygems_version: 1.3.7
|
130
|
+
signing_key:
|
131
|
+
specification_version: 3
|
132
|
+
summary: The Redis first aid!
|
133
|
+
test_files: []
|
134
|
+
|