Class: Bg::Asyncable
- Inherits:
-
Object
- Object
- Bg::Asyncable
- Defined in:
- lib/bg/asyncable.rb
Defined Under Namespace
Modules: Behavior Classes: Wrapper
Instance Attribute Summary collapse
-
#delay ⇒ Object
readonly
Returns the value of attribute delay.
-
#object ⇒ Object
readonly
Returns the value of attribute object.
Instance Method Summary collapse
-
#initialize(object, delay: 0) ⇒ Asyncable
constructor
A new instance of Asyncable.
- #method_missing(name, *args) ⇒ Object
- #respond_to?(name) ⇒ Boolean
Constructor Details
#initialize(object, delay: 0) ⇒ Asyncable
Returns a new instance of Asyncable.
35 36 37 38 39 40 |
# File 'lib/bg/asyncable.rb', line 35 def initialize(object, delay: 0) raise ::ArgumentError unless object.is_a?(::GlobalID::Identification) super() @object = object @delay = delay.to_f end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/bg/asyncable.rb', line 42 def method_missing(name, *args) if object.respond_to? name raise ::ArgumentError.new("blocks are not supported") if block_given? begin wrapped = ::Bg::Asyncable::Wrapper.new(object.to_global_id, delay: delay) wrapped.async.invoke_method name, *args rescue ::StandardError => e raise ::ArgumentError.new("Failed to execute method asynchronously! <#{object.class.name}##{name}> #{e.}") ensure return end end super end |
Instance Attribute Details
#delay ⇒ Object (readonly)
Returns the value of attribute delay.
33 34 35 |
# File 'lib/bg/asyncable.rb', line 33 def delay @delay end |
#object ⇒ Object (readonly)
Returns the value of attribute object.
33 34 35 |
# File 'lib/bg/asyncable.rb', line 33 def object @object end |
Instance Method Details
#respond_to?(name) ⇒ Boolean
57 58 59 60 |
# File 'lib/bg/asyncable.rb', line 57 def respond_to?(name) return true if object.respond_to? name super end |