ook 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.
- checksums.yaml +7 -0
- data/.gems +3 -0
- data/LICENSE +19 -0
- data/README.md +59 -0
- data/lib/ook.rb +32 -0
- data/makefile +4 -0
- data/ook.gemspec +15 -0
- data/test/ook_test.rb +24 -0
- metadata +78 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e6f958c7bf8f4e80086d023c35343110f5765041
|
4
|
+
data.tar.gz: ddc6d658b56fc63e8f81a78e6af09a9479f305bd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6dfef27e8180bdcf50de1edf8341b10662b4a6d5ebd49bd42416778118ac2ea3a61903aef1ec7da3c19270486b8ad4da4b866293248918be6dcb4647d72256d9
|
7
|
+
data.tar.gz: 2dd61beebbd4a498b3b6ac3b9b4a620c159d72b621221c51b5b43bf3f71707cbae2f68596e6f8272cd4839cb8109afc18453da395bfe04d5d0dc37988512e7ec
|
data/.gems
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2014 Michel Martens
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
Ook
|
2
|
+
===
|
3
|
+
|
4
|
+
Object Oriented Keys for Redis.
|
5
|
+
|
6
|
+
Description
|
7
|
+
-----------
|
8
|
+
|
9
|
+
Interact with [Redis][redis] keys in an object oriented way.
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
# Create an instance of Ook by passing
|
13
|
+
# a Redis client and a key.
|
14
|
+
k = Ook.new(Redic.new, "foo")
|
15
|
+
|
16
|
+
# As it depends on [Nido][nido], you can
|
17
|
+
# append strings to the original namespace:
|
18
|
+
k["bar"]["baz"].to_s #=> "foo:bar:baz"
|
19
|
+
|
20
|
+
# And if you call Redis commands on it,
|
21
|
+
# the key will be inserted as the second
|
22
|
+
# parameter when sent to the Redis client:
|
23
|
+
k.call("SET", 42") # SET foo 42
|
24
|
+
k.call("GET") # GET foo
|
25
|
+
```
|
26
|
+
|
27
|
+
Usage
|
28
|
+
-----
|
29
|
+
|
30
|
+
The external API is very similar to that of [Nido][nido], but in
|
31
|
+
addition you need to suply a Redis client. For a compatible
|
32
|
+
client, check [Redic][redic].
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
ns = Ook.new(Redic.new, "foo")
|
36
|
+
|
37
|
+
ns["bar"]["baz"].call("LPUSH", "42")
|
38
|
+
ns["bar"]["baz"].call("LLEN") #=> 1
|
39
|
+
|
40
|
+
ns2 = ns["bar"]["baz"]
|
41
|
+
ns2.call("LLEN") #=> 1
|
42
|
+
```
|
43
|
+
|
44
|
+
And you can use any object as a key, not only strings:
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
ns[:bar][42] #=> "foo:bar:42"
|
48
|
+
```
|
49
|
+
|
50
|
+
[nido]: https://github.com/soveran/nido
|
51
|
+
[redic]: https://github.com/amakawa/redic
|
52
|
+
[redis]: http://redis.io
|
53
|
+
|
54
|
+
Installation
|
55
|
+
------------
|
56
|
+
|
57
|
+
```
|
58
|
+
$ gem install ook
|
59
|
+
```
|
data/lib/ook.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require "nido"
|
2
|
+
|
3
|
+
class Ook
|
4
|
+
|
5
|
+
# The Redis client can be swapped at any point.
|
6
|
+
attr_accessor :redis
|
7
|
+
|
8
|
+
# Receive a Redis client and a key. There are no restrictions
|
9
|
+
# regardin the type of the Redis client, but it must respond to
|
10
|
+
# `call` and the signature must be identical to that of Redic.
|
11
|
+
def initialize(redis, key)
|
12
|
+
@ns = Nido.new(key)
|
13
|
+
@redis = redis
|
14
|
+
end
|
15
|
+
|
16
|
+
# The passed key will be appended to the previous namespace.
|
17
|
+
def [](key)
|
18
|
+
@ns = @ns[key]
|
19
|
+
self
|
20
|
+
end
|
21
|
+
|
22
|
+
# Return an instance of Nido with the current value.
|
23
|
+
def to_s
|
24
|
+
@ns
|
25
|
+
end
|
26
|
+
|
27
|
+
# Call commands on the Redis client after inserting the key
|
28
|
+
# in the second position. Return the result of the command.
|
29
|
+
def call(cmd, *args)
|
30
|
+
@redis.call(cmd, @ns, *args)
|
31
|
+
end
|
32
|
+
end
|
data/makefile
ADDED
data/ook.gemspec
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "ook"
|
3
|
+
s.version = "0.0.1"
|
4
|
+
s.summary = "Object Oriented Keys for Redis"
|
5
|
+
s.description = "Call Redis commands on keys created with Nido"
|
6
|
+
s.authors = ["Michel Martens"]
|
7
|
+
s.email = ["michel@soveran.com"]
|
8
|
+
s.homepage = "http://github.com/soveran/ook"
|
9
|
+
|
10
|
+
s.files = `git ls-files`.split("\n")
|
11
|
+
|
12
|
+
s.add_dependency "nido"
|
13
|
+
|
14
|
+
s.add_development_dependency "cutest"
|
15
|
+
end
|
data/test/ook_test.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require "redic"
|
2
|
+
require_relative "../lib/ook.rb"
|
3
|
+
|
4
|
+
scope do
|
5
|
+
test "namespaces" do
|
6
|
+
k1 = Ook.new(Redic.new, "foo")
|
7
|
+
|
8
|
+
assert_equal "foo:bar", k1["bar"].to_s
|
9
|
+
end
|
10
|
+
|
11
|
+
test "call Redis commands on Redic instance" do
|
12
|
+
k1 = Ook.new(Redic.new, "foo")
|
13
|
+
|
14
|
+
assert_equal "OK", k1.call("SET", 42)
|
15
|
+
assert_equal "42", k1.call("GET")
|
16
|
+
end
|
17
|
+
|
18
|
+
test "swap Redis client" do
|
19
|
+
k1 = Ook.new(Redic.new, "foo")
|
20
|
+
k1.redis = Redic.new
|
21
|
+
|
22
|
+
assert_equal "foo", k1.call("ECHO")
|
23
|
+
end
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ook
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Michel Martens
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-02-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nido
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: cutest
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Call Redis commands on keys created with Nido
|
42
|
+
email:
|
43
|
+
- michel@soveran.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gems
|
49
|
+
- LICENSE
|
50
|
+
- README.md
|
51
|
+
- lib/ook.rb
|
52
|
+
- makefile
|
53
|
+
- ook.gemspec
|
54
|
+
- test/ook_test.rb
|
55
|
+
homepage: http://github.com/soveran/ook
|
56
|
+
licenses: []
|
57
|
+
metadata: {}
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options: []
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - '>='
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
requirements: []
|
73
|
+
rubyforge_project:
|
74
|
+
rubygems_version: 2.0.3
|
75
|
+
signing_key:
|
76
|
+
specification_version: 4
|
77
|
+
summary: Object Oriented Keys for Redis
|
78
|
+
test_files: []
|