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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7fcc79980b6028227e6bb9da5cdbad37a08611e0
4
- data.tar.gz: b3b788992af595d277bc4c4c9c83be4f9624c50d
3
+ metadata.gz: 56ec597997603d5c17fef41f9bda0a86d92ea1db
4
+ data.tar.gz: 49140040673bd82d017ac6993e18f939ad2de476
5
5
  SHA512:
6
- metadata.gz: b919b59f338b30ac0842f441276efabdaa1d4e8d9b0d5150aa9a989ef79713a7847e4db82caf4f2aeeab6898106711466e064bc1bd57b5cd266d5473ff9eae64
7
- data.tar.gz: 8de1698298a0ca5ecd23f1109f4477bc4b6b9fcbd5a2c8fa2cf04cb46bc19ca1aa21b973cc7f392886819120a22d24a4fa464500aa3469c75146f00d71256af7
6
+ metadata.gz: c51a4b71a5f812c157e6bb5a1662ad68f7703cb9bf6c9a715a5c654ee8fa39755b63f232280ba4291e41f039d63f474d6e77a213cbbdf51dd8d1d03d791294a6
7
+ data.tar.gz: e7a42103e32ef13723dd83647df233054f89ea6fe4a875b5fd9c012dd16f47d2f70f0c3ccef9872c95c981aa1905285f96b599c8dd0b2c21a641284869b9c2b4
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- leakybucket (0.0.1)
4
+ leakybucket (0.0.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -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] || default_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
@@ -1,3 +1,3 @@
1
1
  module Leakybucket
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/leakybucket.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'leakybucket/version'
2
2
  require 'leakybucket/bucket'
3
+ require 'leakybucket/manager'
3
4
 
4
5
  module Leakybucket
5
6
  end
@@ -54,3 +54,4 @@ describe Leakybucket::Bucket do
54
54
  out.should eql('leaking with value -2')
55
55
  end
56
56
  end
57
+
@@ -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.2
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/leakybucket_spec.rb
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/leakybucket_spec.rb
101
+ - spec/leakybucket_bucket_spec.rb
102
+ - spec/leakybucket_manager_spec.rb