leakybucket 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/leakybucket/bucket.rb +5 -4
- data/lib/leakybucket/manager.rb +26 -0
- data/lib/leakybucket/version.rb +1 -1
- data/lib/leakybucket.rb +1 -0
- data/spec/{leakybucket_spec.rb → leakybucket_bucket_spec.rb} +1 -0
- data/spec/leakybucket_manager_spec.rb +27 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 56ec597997603d5c17fef41f9bda0a86d92ea1db
|
4
|
+
data.tar.gz: 49140040673bd82d017ac6993e18f939ad2de476
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c51a4b71a5f812c157e6bb5a1662ad68f7703cb9bf6c9a715a5c654ee8fa39755b63f232280ba4291e41f039d63f474d6e77a213cbbdf51dd8d1d03d791294a6
|
7
|
+
data.tar.gz: e7a42103e32ef13723dd83647df233054f89ea6fe4a875b5fd9c012dd16f47d2f70f0c3ccef9872c95c981aa1905285f96b599c8dd0b2c21a641284869b9c2b4
|
data/Gemfile.lock
CHANGED
data/lib/leakybucket/bucket.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
class Leakybucket::Bucket
|
2
2
|
|
3
|
-
attr_accessor :limit, :value, :leaking_callback
|
3
|
+
attr_accessor :limit, :value, :leaking_callback, :key
|
4
4
|
|
5
|
-
def initialize(options = {})
|
6
|
-
self.limit = options[:limit]
|
7
|
-
self.value = limit
|
5
|
+
def initialize(options = {}, key = '')
|
6
|
+
self.limit = default_options.merge(options)[:limit]
|
7
|
+
self.value = self.limit
|
8
|
+
self.key = key
|
8
9
|
end
|
9
10
|
|
10
11
|
def default_options
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
|
3
|
+
class Leakybucket::Manager
|
4
|
+
|
5
|
+
attr_accessor :buckets, :default_options
|
6
|
+
|
7
|
+
def initialize(default_options = {})
|
8
|
+
self.default_options = default_options
|
9
|
+
self.buckets = {}
|
10
|
+
end
|
11
|
+
|
12
|
+
def generate_key
|
13
|
+
SecureRandom.uuid
|
14
|
+
end
|
15
|
+
|
16
|
+
def create_bucket(options = {})
|
17
|
+
key = generate_key
|
18
|
+
b = Leakybucket::Bucket.new(default_options.merge(options), key)
|
19
|
+
buckets[key] = b
|
20
|
+
b
|
21
|
+
end
|
22
|
+
|
23
|
+
def remove_bucket(key)
|
24
|
+
buckets.delete(key)
|
25
|
+
end
|
26
|
+
end
|
data/lib/leakybucket/version.rb
CHANGED
data/lib/leakybucket.rb
CHANGED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'leakybucket'
|
2
|
+
|
3
|
+
describe Leakybucket::Bucket do
|
4
|
+
it 'should create buckets' do
|
5
|
+
m = Leakybucket::Manager.new
|
6
|
+
b1 = m.create_bucket(limit: 5)
|
7
|
+
b1.limit.should eql(5)
|
8
|
+
m.buckets.size.should eql(1)
|
9
|
+
m.buckets[b1.key].should eql(b1)
|
10
|
+
|
11
|
+
b2 = m.create_bucket(limit: 3)
|
12
|
+
b2.limit.should eql(3)
|
13
|
+
m.buckets.size.should eql(2)
|
14
|
+
b1.key.should_not eql(b2.key)
|
15
|
+
m.buckets[b2.key].should eql(b2)
|
16
|
+
m.buckets[b2.key].should_not eql(b1)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should remove buckets' do
|
20
|
+
m = Leakybucket::Manager.new
|
21
|
+
b1 = m.create_bucket(limit: 5)
|
22
|
+
m.buckets.size.should eql(1)
|
23
|
+
b2 = m.remove_bucket(b1.key)
|
24
|
+
m.buckets.size.should eql(0)
|
25
|
+
b1.should eq(b2)
|
26
|
+
end
|
27
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: leakybucket
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lukas Elmer
|
@@ -69,8 +69,10 @@ files:
|
|
69
69
|
- leakybucket.gemspec
|
70
70
|
- lib/leakybucket.rb
|
71
71
|
- lib/leakybucket/bucket.rb
|
72
|
+
- lib/leakybucket/manager.rb
|
72
73
|
- lib/leakybucket/version.rb
|
73
|
-
- spec/
|
74
|
+
- spec/leakybucket_bucket_spec.rb
|
75
|
+
- spec/leakybucket_manager_spec.rb
|
74
76
|
homepage: https://github.com/lukaselmer/leakybucket
|
75
77
|
licenses:
|
76
78
|
- MIT
|
@@ -96,4 +98,5 @@ signing_key:
|
|
96
98
|
specification_version: 4
|
97
99
|
summary: Provides an API to manage leaky buckets.
|
98
100
|
test_files:
|
99
|
-
- spec/
|
101
|
+
- spec/leakybucket_bucket_spec.rb
|
102
|
+
- spec/leakybucket_manager_spec.rb
|