Class: Leakybucket::Manager

Inherits:
Object
  • Object
show all
Defined in:
lib/leakybucket/manager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(default_options = {}) ⇒ Manager

Returns a new instance of Manager.



7
8
9
10
# File 'lib/leakybucket/manager.rb', line 7

def initialize(default_options = {})
  self.default_options = default_options
  self.buckets = {}
end

Instance Attribute Details

#bucketsObject

Returns the value of attribute buckets.



5
6
7
# File 'lib/leakybucket/manager.rb', line 5

def buckets
  @buckets
end

#default_optionsObject

Returns the value of attribute default_options.



5
6
7
# File 'lib/leakybucket/manager.rb', line 5

def default_options
  @default_options
end

Instance Method Details

#create_bucket(options = {}) ⇒ Object



16
17
18
19
20
21
# File 'lib/leakybucket/manager.rb', line 16

def create_bucket(options = {})
  key = options[:key] || generate_key
  b = Leakybucket::Bucket.new(default_options.merge(options), key)
  buckets[key] = b
  b
end

#generate_keyObject



12
13
14
# File 'lib/leakybucket/manager.rb', line 12

def generate_key
  SecureRandom.uuid
end

#remove_bucket(key) ⇒ Object



23
24
25
# File 'lib/leakybucket/manager.rb', line 23

def remove_bucket(key)
  buckets.delete(key)
end