Class: Droonga::Client::RateLimiter

Inherits:
Object
  • Object
show all
Defined in:
lib/droonga/client/rate-limiter.rb

Constant Summary collapse

DEFAULT_LIMIT =
100
NO_LIMIT =
-1

Instance Method Summary collapse

Constructor Details

#initialize(client, messages_per_second) ⇒ RateLimiter

Returns a new instance of RateLimiter.



22
23
24
25
26
# File 'lib/droonga/client/rate-limiter.rb', line 22

def initialize(client, messages_per_second)
  @client = client
  @messages_per_second = messages_per_second
  @diff_in_seconds_per_message = 1.0 / @messages_per_second
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/droonga/client/rate-limiter.rb', line 34

def method_missing(name, *args, &block)
  if @client.respond_to?(name)
    @client.__send__(name, *args, &block)
  else
    super
  end
end

Instance Method Details

#send(*args, &block) ⇒ Object



28
29
30
31
32
# File 'lib/droonga/client/rate-limiter.rb', line 28

def send(*args, &block)
  limit do
    @client.send(*args, &block)
  end
end