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
-
#callable ⇒ Object
readonly
Returns the value of attribute callable.
Instance Method Summary collapse
- #complete? ⇒ Boolean
-
#initialize(future, model, callable = nil) ⇒ Deferred
constructor
A new instance of Deferred.
- #method_missing(method, *args, &block) ⇒ Object
Constructor Details
#initialize(future, model, callable = nil) ⇒ Deferred
Returns 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
#method_missing(method, *args, &block) ⇒ Object
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
#callable ⇒ Object (readonly)
Returns the value of attribute callable.
13 14 15 |
# File 'lib/weary/deferred.rb', line 13 def callable @callable end |
Instance Method Details
#complete? ⇒ Boolean
22 23 24 |
# File 'lib/weary/deferred.rb', line 22 def complete? !!@target end |