Class: RailsAsyncMethods::AsyncWrapper
- Defined in:
- lib/rails_async_methods/wrapper/async_wrapper.rb
Defined Under Namespace
Classes: NotPersistedError
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#receiver ⇒ Object
readonly
Returns the value of attribute receiver.
Instance Method Summary collapse
-
#initialize(receiver, options = {}) ⇒ AsyncWrapper
constructor
A new instance of AsyncWrapper.
- #method_missing(method, *args, **kwargs) ⇒ Object
- #respond_to_missing?(method) ⇒ Boolean
Constructor Details
#initialize(receiver, options = {}) ⇒ AsyncWrapper
Returns a new instance of AsyncWrapper.
8 9 10 11 |
# File 'lib/rails_async_methods/wrapper/async_wrapper.rb', line 8 def initialize(receiver, = {}) @receiver = receiver @options = RailsAsyncMethods::ActiveJobOptionsParser.new() end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, **kwargs) ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/rails_async_methods/wrapper/async_wrapper.rb', line 13 def method_missing(method, *args, **kwargs) raise NotPersistedError, 'Instance must be persisted to run asynchronously' unless receiver.persisted? raise TypeError, 'Cannot pass a block to an asynchronous method' if block_given? if @receiver.methods.include? method @options.job.set(**@options.to_h).perform_later(@receiver, method, *args, **kwargs) else super end end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/rails_async_methods/wrapper/async_wrapper.rb', line 6 def @options end |
#receiver ⇒ Object (readonly)
Returns the value of attribute receiver.
6 7 8 |
# File 'lib/rails_async_methods/wrapper/async_wrapper.rb', line 6 def receiver @receiver end |
Instance Method Details
#respond_to_missing?(method) ⇒ Boolean
24 25 26 |
# File 'lib/rails_async_methods/wrapper/async_wrapper.rb', line 24 def respond_to_missing?(method) @receiver.methods.include?(method) || super end |