Class: Weary::Deferred
- Inherits:
-
Object
- Object
- Weary::Deferred
- Defined in:
- lib/weary/deferred.rb
Overview
A handy abstract proxy class that is used to proxy a domain model in an asynchronous fashion. Useful if you're not interested in a Weary::Response object, but you want to pass that into a domain object when the response is available.
Instance Attribute Summary (collapse)
-
- (Object) callable
readonly
Returns the value of attribute callable.
Instance Method Summary (collapse)
- - (Boolean) complete?
-
- (Deferred) initialize(future, model, callable = nil)
constructor
A new instance of Deferred.
- - (Object) method_missing(method, *args, &block)
Constructor Details
- (Deferred) initialize(future, model, callable = nil)
A new instance of Deferred
15 16 17 18 19 20 |
# File 'lib/weary/deferred.rb', line 15 def initialize(future, model, callable=nil) @future = future @model = model @callable = callable || ::Proc.new{|klass, response| klass.new(response) } @target = nil end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
- (Object) method_missing(method, *args, &block)
26 27 28 29 30 31 32 33 |
# File 'lib/weary/deferred.rb', line 26 def method_missing(method, *args, &block) if @model.method_defined? method @target ||= @callable.call @model, @future @target.send(method, *args, &block) else super end end |
Instance Attribute Details
- (Object) callable (readonly)
Returns the value of attribute callable
13 14 15 |
# File 'lib/weary/deferred.rb', line 13 def callable @callable end |
Instance Method Details
- (Boolean) complete?
22 23 24 |
# File 'lib/weary/deferred.rb', line 22 def complete? !!@target end |