Class: ThrottledObject::Proxy

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/throttled_object/proxy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, options = {}) ⇒ Proxy

Returns a new instance of Proxy.



8
9
10
11
12
13
14
15
# File 'lib/throttled_object/proxy.rb', line 8

def initialize(object, options = {})
  super object
  @lock              = options.fetch(:lock)
  @blocking          = options.fetch :blocking, true
  @lock_method       = @blocking ? :synchronize : :synchronize!
  throttled_methods  = options.fetch :methods, nil
  @throttled_methods = throttled_methods && throttled_methods.map(&:to_sym)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object (private)



23
24
25
26
27
28
29
# File 'lib/throttled_object/proxy.rb', line 23

def method_missing(m, *args, &block)
  if lock_method?(m)
    @lock.send(@lock_method) { super }
  else
    super
  end
end

Instance Attribute Details

#lockObject

Returns the value of attribute lock.



6
7
8
# File 'lib/throttled_object/proxy.rb', line 6

def lock
  @lock
end

#throttled_methodsObject

Returns the value of attribute throttled_methods.



6
7
8
# File 'lib/throttled_object/proxy.rb', line 6

def throttled_methods
  @throttled_methods
end