Class: ThrottledObject::Proxy
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- ThrottledObject::Proxy
- Defined in:
- lib/throttled_object/proxy.rb
Instance Attribute Summary collapse
-
#lock ⇒ Object
Returns the value of attribute lock.
-
#throttled_methods ⇒ Object
Returns the value of attribute throttled_methods.
Instance Method Summary collapse
-
#initialize(object, options = {}) ⇒ Proxy
constructor
A new instance of Proxy.
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, = {}) super object @lock = .fetch(:lock) @blocking = .fetch :blocking, true @lock_method = @blocking ? :synchronize : :synchronize! throttled_methods = .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
#lock ⇒ Object
Returns the value of attribute lock.
6 7 8 |
# File 'lib/throttled_object/proxy.rb', line 6 def lock @lock end |
#throttled_methods ⇒ Object
Returns the value of attribute throttled_methods.
6 7 8 |
# File 'lib/throttled_object/proxy.rb', line 6 def throttled_methods @throttled_methods end |