nido 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7b6ace7778462d82d73a638d2620395e436241eb
4
+ data.tar.gz: 1661f54773ccd18e5de06478d6ff07aa9158e811
5
+ SHA512:
6
+ metadata.gz: 9aef52e92c6cd4c4886ad37885c05098a8d0075ba5ae3bfabbc1973a5a470d0bad3ad741d03e9abcb3b530dd659c4e8953eeb1aa303686d9b54a337fb3b3ffca
7
+ data.tar.gz: e8b2fed1af1445c2ade7a3644250f35d95d04606c62fabfa352b340b450bdbf5a0e677f69379ac4d07b4b48669483f406e79e6a9becdfc121244a4a024362dc0
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2013 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,70 @@
1
+ Nido
2
+ ====
3
+
4
+ Structured keys helper.
5
+
6
+ Description
7
+ -----------
8
+
9
+ If you are familiar with databases like [Redis](http://code.google.com/p/redis)
10
+ and libraries like [Ohm](http://ohm.keyvalue.org) you already know how
11
+ important it is to craft the keys that will hold the data.
12
+
13
+ >> redis = Redis.new
14
+ >> redis.sadd("event:3:attendees", "Albert")
15
+ >> redis.smembers("event:3:attendees")
16
+ => ["Albert"]
17
+
18
+ It is a design pattern in key-value databases to use the key to simulate
19
+ structure, and you can read more about this in the [case study for a
20
+ Twitter clone](http://code.google.com/p/redis/wiki/TwitterAlikeExample).
21
+
22
+ Nido helps you generate those keys by providing chainable namespaces:
23
+
24
+ >> r = Redis.new
25
+ >> event = Nido.new("event")
26
+ >> r.sadd(event[3][:attendees], "Albert")
27
+ >> r.smembers(event[3][:attendees])
28
+ => ["Albert"]
29
+
30
+ Usage
31
+ -----
32
+
33
+ To create a new namespace:
34
+
35
+ >> ns = Nido.new("foo")
36
+ => "foo"
37
+
38
+ >> ns["bar"]
39
+ => "foo:bar"
40
+
41
+ >> ns["bar"]["baz"]["qux"]
42
+ => "foo:bar:baz:qux"
43
+
44
+ And you can use any object as a key, not only strings:
45
+
46
+ >> ns[:bar][42]
47
+ => "foo:bar:42"
48
+
49
+ In a more realistic tone, lets assume you are working with Redis and
50
+ dealing with events:
51
+
52
+ >> events = Nido.new("events")
53
+ => "events"
54
+
55
+ >> id = r.incr(events[:id])
56
+ => 1
57
+
58
+ >> r.sadd(events[id][:attendees], "Albert")
59
+ => "OK"
60
+
61
+ >> meetup = events[id]
62
+ => "events:1"
63
+
64
+ >> r.smembers(meetup[:attendees])
65
+ => ["Albert"]
66
+
67
+ Installation
68
+ ------------
69
+
70
+ $ gem install nido
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ task :test do
2
+ require "cutest"
3
+ Cutest.run(Dir["test/nido*"])
4
+ end
5
+
6
+ task :default => :test
data/lib/nido.rb ADDED
@@ -0,0 +1,9 @@
1
+ class Nido < String
2
+ def initialize(key)
3
+ super(key.to_s)
4
+ end
5
+
6
+ def [](key)
7
+ self.class.new("#{self}:#{key}")
8
+ end
9
+ end
data/nido.gemspec ADDED
@@ -0,0 +1,20 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "nido"
3
+ s.version = "0.0.1"
4
+ s.summary = "Structured keys helper"
5
+ s.description = "It is a design pattern in key-value databases to use the key to simulate structure, and Nido can take care of that."
6
+ s.authors = ["Michel Martens"]
7
+ s.email = ["michel@soveran.com"]
8
+ s.homepage = "http://github.com/soveran/nido"
9
+
10
+ s.files = Dir[
11
+ "LICENSE",
12
+ "README.md",
13
+ "Rakefile",
14
+ "lib/**/*.rb",
15
+ "*.gemspec",
16
+ "test/*.*"
17
+ ]
18
+
19
+ s.add_development_dependency "cutest"
20
+ end
data/test/nido_test.rb ADDED
@@ -0,0 +1,35 @@
1
+ require_relative "../lib/nido.rb"
2
+
3
+ # Creating namespaces.
4
+ scope do
5
+ test "return the namespace" do
6
+ n1 = Nido.new("foo")
7
+ assert "foo" == n1
8
+ end
9
+
10
+ test "prepend the namespace" do
11
+ n1 = Nido.new("foo")
12
+ assert "foo:bar" == n1["bar"]
13
+ end
14
+
15
+ test "work in more than one level" do
16
+ n1 = Nido.new("foo")
17
+ n2 = Nido.new(n1["bar"])
18
+ assert "foo:bar:baz" == n2["baz"]
19
+ end
20
+
21
+ test "be chainable" do
22
+ n1 = Nido.new("foo")
23
+ assert "foo:bar:baz" == n1["bar"]["baz"]
24
+ end
25
+
26
+ test "accept symbols" do
27
+ n1 = Nido.new(:foo)
28
+ assert "foo:bar" == n1[:bar]
29
+ end
30
+
31
+ test "accept numbers" do
32
+ n1 = Nido.new("foo")
33
+ assert "foo:3" == n1[3]
34
+ end
35
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nido
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: 2013-04-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: cutest
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: It is a design pattern in key-value databases to use the key to simulate
28
+ structure, and Nido can take care of that.
29
+ email:
30
+ - michel@soveran.com
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - LICENSE
36
+ - README.md
37
+ - Rakefile
38
+ - lib/nido.rb
39
+ - nido.gemspec
40
+ - test/nido_test.rb
41
+ homepage: http://github.com/soveran/nido
42
+ licenses: []
43
+ metadata: {}
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubyforge_project:
60
+ rubygems_version: 2.0.3
61
+ signing_key:
62
+ specification_version: 4
63
+ summary: Structured keys helper
64
+ test_files: []