roulette 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/roulette.rb +8 -5
- data/pkg/roulette-0.0.1.gem +0 -0
- data/roulette.gemspec +72 -0
- data/spec/roulette/roulette_spec.rb +17 -5
- data/spec/roulette/transaction_spec.rb +18 -12
- metadata +4 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
data/lib/roulette.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
1
|
# Roulette.config([Redis.new(..), Redis.new(...)])
|
3
2
|
#
|
4
3
|
# r = Roulette.new([Redis.new(..), Redis.new(...)])
|
@@ -16,7 +15,7 @@ class Roulette
|
|
16
15
|
attr_accessor :stores
|
17
16
|
|
18
17
|
def initialize(*stores)
|
19
|
-
self.stores = stores
|
18
|
+
self.stores = stores.flatten
|
20
19
|
end
|
21
20
|
|
22
21
|
def method_missing(method_name, *args, &blk)
|
@@ -26,14 +25,18 @@ class Roulette
|
|
26
25
|
class Transaction
|
27
26
|
attr_accessor :key, :args, :stores
|
28
27
|
|
28
|
+
|
29
29
|
def initialize(stores, *args)
|
30
30
|
self.stores = stores
|
31
31
|
self.args = *args
|
32
|
-
|
32
|
+
extract_key
|
33
33
|
end
|
34
34
|
|
35
|
-
def
|
36
|
-
|
35
|
+
def extract_key
|
36
|
+
# there is a 'bug' with something in the rails library that when loaded will
|
37
|
+
# produce Roulette::Transaction.new([], "key") # => "k" instead of "key"
|
38
|
+
# this is a fix for that, but i don't know what in rails env causes this discrepency
|
39
|
+
self.key = args.is_a?(Array) ? args.first.to_s : args.to_s
|
37
40
|
end
|
38
41
|
|
39
42
|
def fire(method)
|
data/pkg/roulette-0.0.1.gem
CHANGED
Binary file
|
data/roulette.gemspec
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{roulette}
|
8
|
+
s.version = "0.0.2"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Schneems"]
|
12
|
+
s.date = %q{2011-07-11}
|
13
|
+
s.description = %q{
|
14
|
+
Super easy pre-sharding for your ruby NOSQL store. Presharding is used to naively scale your data-stores horizontally.
|
15
|
+
}
|
16
|
+
s.email = %q{richard.schneeman@gmail.com}
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"README.md"
|
19
|
+
]
|
20
|
+
s.files = [
|
21
|
+
".rvmrc",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"README.md",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"autotest/discover.rb",
|
28
|
+
"lib/roulette.rb",
|
29
|
+
"license.txt",
|
30
|
+
"pkg/roulette-.gem",
|
31
|
+
"pkg/roulette-0.0.1.gem",
|
32
|
+
"roulette.gemspec",
|
33
|
+
"spec/roulette/roulette_spec.rb",
|
34
|
+
"spec/roulette/transaction_spec.rb",
|
35
|
+
"spec/spec_helper.rb"
|
36
|
+
]
|
37
|
+
s.homepage = %q{http://github.com/Schnems/roulette}
|
38
|
+
s.licenses = ["MIT"]
|
39
|
+
s.require_paths = ["lib"]
|
40
|
+
s.rubygems_version = %q{1.6.2}
|
41
|
+
s.summary = %q{Pre-Sharding so simple you'll shoot yourself :p}
|
42
|
+
s.test_files = [
|
43
|
+
"spec/roulette/roulette_spec.rb",
|
44
|
+
"spec/roulette/transaction_spec.rb",
|
45
|
+
"spec/spec_helper.rb"
|
46
|
+
]
|
47
|
+
|
48
|
+
if s.respond_to? :specification_version then
|
49
|
+
s.specification_version = 3
|
50
|
+
|
51
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
52
|
+
s.add_development_dependency(%q<rake>, ["~> 0.8.7"])
|
53
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
54
|
+
s.add_development_dependency(%q<autotest-standalone>, [">= 0"])
|
55
|
+
s.add_development_dependency(%q<autotest-growl>, [">= 0"])
|
56
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
57
|
+
else
|
58
|
+
s.add_dependency(%q<rake>, ["~> 0.8.7"])
|
59
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
60
|
+
s.add_dependency(%q<autotest-standalone>, [">= 0"])
|
61
|
+
s.add_dependency(%q<autotest-growl>, [">= 0"])
|
62
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
63
|
+
end
|
64
|
+
else
|
65
|
+
s.add_dependency(%q<rake>, ["~> 0.8.7"])
|
66
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
67
|
+
s.add_dependency(%q<autotest-standalone>, [">= 0"])
|
68
|
+
s.add_dependency(%q<autotest-growl>, [">= 0"])
|
69
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
class FakeKeyValueStore
|
3
|
-
|
3
|
+
|
4
4
|
end
|
5
5
|
|
6
6
|
|
@@ -10,25 +10,37 @@ describe Roulette do
|
|
10
10
|
@kv_store = FakeKeyValueStore.new
|
11
11
|
@roulette = Roulette.new(@kv_store)
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
it 'passes, key and value to the stored KV_store' do
|
15
15
|
@kv_store.should_receive(:sadd).with("foo", "bar")
|
16
16
|
@roulette.sadd("foo", "bar")
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
it 'passes, key and value to the stored KV_store' do
|
20
20
|
@kv_store.should_receive(:sadd).with("foo", "bar")
|
21
21
|
@roulette.sadd("foo", "bar")
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
it 'passes key to the stored KV_store' do
|
25
25
|
@kv_store.should_receive(:scard).with("foo")
|
26
26
|
@roulette.scard("foo")
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
it 'passes arbitrary number of elements to the stored KV_store' do
|
30
30
|
@kv_store.should_receive(:fake_method).with(1,2,3,4,5,6,7,8,9,0)
|
31
31
|
@roulette.fake_method(1,2,3,4,5,6,7,8,9,0)
|
32
32
|
end
|
33
33
|
end
|
34
|
+
|
35
|
+
describe 'stores' do
|
36
|
+
before do
|
37
|
+
@kv_store = FakeKeyValueStore.new
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'passes multiple stores into a single array (doesn make an array of an array)' do
|
41
|
+
store_array = [@kv_store, @kv_store, @kv_store]
|
42
|
+
@roulette = Roulette.new(store_array)
|
43
|
+
@roulette.stores.should eq(store_array)
|
44
|
+
end
|
45
|
+
end
|
34
46
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
class FakeKeyValueStore
|
3
|
-
|
3
|
+
|
4
4
|
end
|
5
5
|
|
6
6
|
|
@@ -10,7 +10,7 @@ describe Roulette::Transaction do
|
|
10
10
|
@key = "key"
|
11
11
|
@args = [@key, "value"]
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
describe '#new' do
|
15
15
|
it "keeps args, stores, and key" do
|
16
16
|
transaction = Roulette::Transaction.new([@kv_store], *@args)
|
@@ -19,29 +19,35 @@ describe Roulette::Transaction do
|
|
19
19
|
transaction.args.should eq(@args)
|
20
20
|
end
|
21
21
|
end
|
22
|
-
|
23
|
-
describe '#
|
22
|
+
|
23
|
+
describe '#extract_key' do
|
24
|
+
it "pulls out the key even if there is only one arg" do
|
25
|
+
key = "foo"
|
26
|
+
transaction = Roulette::Transaction.new([], key)
|
27
|
+
transaction.extract_key.should eq(key)
|
28
|
+
end
|
29
|
+
|
24
30
|
it "pulls out the key" do
|
25
|
-
transaction = Roulette::Transaction.new([
|
26
|
-
transaction.
|
31
|
+
transaction = Roulette::Transaction.new([], *@args)
|
32
|
+
transaction.extract_key.should eq(@key)
|
27
33
|
end
|
28
34
|
end
|
29
|
-
|
35
|
+
|
30
36
|
describe '#select_store' do
|
31
37
|
it "picks a store" do
|
32
38
|
transaction = Roulette::Transaction.new([@kv_store], *@args)
|
33
|
-
store = transaction.send :select_store
|
39
|
+
store = transaction.send :select_store
|
34
40
|
store.should eq(@kv_store)
|
35
41
|
end
|
36
|
-
|
42
|
+
|
37
43
|
it "selects different stores for different keys" do
|
38
44
|
@kv_store_deux = FakeKeyValueStore.new
|
39
|
-
store = Roulette::Transaction.new([@kv_store, @kv_store_deux], "key").send :select_store
|
40
|
-
store_deux = Roulette::Transaction.new([@kv_store, @kv_store_deux], "different_key").send :select_store
|
45
|
+
store = Roulette::Transaction.new([@kv_store, @kv_store_deux], "key").send :select_store
|
46
|
+
store_deux = Roulette::Transaction.new([@kv_store, @kv_store_deux], "different_key").send :select_store
|
41
47
|
store.should_not eq(store_deux)
|
42
48
|
end
|
43
49
|
end
|
44
|
-
|
50
|
+
|
45
51
|
describe "#fire" do
|
46
52
|
it "sends a method to a kv_store" do
|
47
53
|
fired_method = :sadd
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: roulette
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Schneems
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-07-
|
13
|
+
date: 2011-07-11 00:00:00 -05:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -88,6 +88,7 @@ files:
|
|
88
88
|
- license.txt
|
89
89
|
- pkg/roulette-.gem
|
90
90
|
- pkg/roulette-0.0.1.gem
|
91
|
+
- roulette.gemspec
|
91
92
|
- spec/roulette/roulette_spec.rb
|
92
93
|
- spec/roulette/transaction_spec.rb
|
93
94
|
- spec/spec_helper.rb
|
@@ -105,7 +106,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
105
106
|
requirements:
|
106
107
|
- - ">="
|
107
108
|
- !ruby/object:Gem::Version
|
108
|
-
hash:
|
109
|
+
hash: 2757344494909302037
|
109
110
|
segments:
|
110
111
|
- 0
|
111
112
|
version: "0"
|