Class: Bg::Deferrable
- Inherits:
-
Object
- Object
- Bg::Deferrable
- Defined in:
- lib/bg/deferrable.rb
Defined Under Namespace
Modules: Behavior
Instance Attribute Summary collapse
-
#object ⇒ Object
readonly
Returns the value of attribute object.
-
#queue ⇒ Object
readonly
Returns the value of attribute queue.
-
#wait ⇒ Object
readonly
Returns the value of attribute wait.
Instance Method Summary collapse
-
#initialize(object, queue: :default, wait: 0) ⇒ Deferrable
constructor
A new instance of Deferrable.
- #method_missing(name, *args) ⇒ Object
- #respond_to?(name) ⇒ Boolean
Constructor Details
#initialize(object, queue: :default, wait: 0) ⇒ Deferrable
Returns a new instance of Deferrable.
15 16 17 18 19 20 |
# File 'lib/bg/deferrable.rb', line 15 def initialize(object, queue: :default, wait: 0) raise ::ArgumentError unless object.is_a?(::GlobalID::Identification) @object = object @queue = queue || :default @wait = wait.to_i end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/bg/deferrable.rb', line 22 def method_missing(name, *args) if object.respond_to? name raise ::ArgumentError.new("blocks are not supported") if block_given? begin if wait > 0 job = ::Bg::DeferredMethodCallJob.set(queue: queue, wait: wait).perform_later object, name.to_s, *args else job = ::Bg::DeferredMethodCallJob.set(queue: queue).perform_later object, name.to_s, *args end rescue ::StandardError => e raise ::ArgumentError.new("Failed to background method call! <#{object.class.name}##{name}> #{e.}") ensure return job end end super end |
Instance Attribute Details
#object ⇒ Object (readonly)
Returns the value of attribute object.
13 14 15 |
# File 'lib/bg/deferrable.rb', line 13 def object @object end |
#queue ⇒ Object (readonly)
Returns the value of attribute queue.
13 14 15 |
# File 'lib/bg/deferrable.rb', line 13 def queue @queue end |
#wait ⇒ Object (readonly)
Returns the value of attribute wait.
13 14 15 |
# File 'lib/bg/deferrable.rb', line 13 def wait @wait end |
Instance Method Details
#respond_to?(name) ⇒ Boolean
40 41 42 43 |
# File 'lib/bg/deferrable.rb', line 40 def respond_to?(name) return true if object.respond_to? name super end |