Class: RateLimit::Memory

Inherits:
Storage show all
Defined in:
lib/ratelimit/bucketbased.rb

Instance Method Summary collapse

Constructor Details

#initializeMemory

Returns a new instance of Memory.



82
83
84
# File 'lib/ratelimit/bucketbased.rb', line 82

def initialize
	@buckets = {}
end

Instance Method Details

#get(name) ⇒ Object

retrieves a named bucket

  • Args :

    • name -> the name of the bucket to be retrieved

  • Returns :

    • the bucket matching the name if found, nil otherwise



91
92
93
# File 'lib/ratelimit/bucketbased.rb', line 91

def get(name)
	@buckets[name]
end

#set(bucket) ⇒ Object

saves a bucket into the storage

  • Args :

    • bucket -> the Bucket to set. The name field in the Bucket option will be used as a key.

  • Returns :

    • the bucket that is provided in the Args



100
101
102
# File 'lib/ratelimit/bucketbased.rb', line 100

def set(bucket)
	@buckets[bucket.name] = bucket
end

#update(bucket) ⇒ Object

updates the key fields that need updating into the storage this is often cheaper for certain types of storage than using set()

  • Args :

    • bucket -> the Bucket to update. The name field in the Bucket option will be used as a key.

  • Returns :

    • nil



110
111
112
# File 'lib/ratelimit/bucketbased.rb', line 110

def update(bucket)
	# already updated
end