Class: Aqua::Stub
- Inherits:
-
Object
- Object
- Aqua::Stub
- Defined in:
- lib/aqua/object/stub.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#delegate ⇒ Object
Returns the value of attribute delegate.
-
#delegate_class ⇒ Object
Returns the value of attribute delegate_class.
-
#delegate_id ⇒ Object
Returns the value of attribute delegate_id.
-
#parent_object ⇒ Object
Returns the value of attribute parent_object.
-
#path_from_parent ⇒ Object
Returns the value of attribute path_from_parent.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(opts) ⇒ Stub
constructor
Builds a new stub object which returns cached/stubbed methods until such a time as a non-cached method is requested.
Constructor Details
#initialize(opts) ⇒ Stub
pass in information about parent, and path to the stub such that method missing replaces stub with actual object being stubbed and delegated to.
Builds a new stub object which returns cached/stubbed methods until such a time as a non-cached method is requested.
17 18 19 20 21 22 23 24 |
# File 'lib/aqua/object/stub.rb', line 17 def initialize(opts) stub_methods( opts[:methods] || {} ) self.delegate_class = opts[:class] self.delegate_id = opts[:id] self.parent_object = opts[:parent] self.path_from_parent = opts[:path] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object (protected)
46 47 48 49 50 51 52 53 |
# File 'lib/aqua/object/stub.rb', line 46 def method_missing( method, *args, &block ) load_delegate if delegate.nil? if delegate delegate.send( method, *args, &block ) else missing_delegate_error end end |
Instance Attribute Details
#delegate ⇒ Object
Returns the value of attribute delegate.
3 4 5 |
# File 'lib/aqua/object/stub.rb', line 3 def delegate @delegate end |
#delegate_class ⇒ Object
Returns the value of attribute delegate_class.
3 4 5 |
# File 'lib/aqua/object/stub.rb', line 3 def delegate_class @delegate_class end |
#delegate_id ⇒ Object
Returns the value of attribute delegate_id.
3 4 5 |
# File 'lib/aqua/object/stub.rb', line 3 def delegate_id @delegate_id end |
#parent_object ⇒ Object
Returns the value of attribute parent_object.
3 4 5 |
# File 'lib/aqua/object/stub.rb', line 3 def parent_object @parent_object end |
#path_from_parent ⇒ Object
Returns the value of attribute path_from_parent.
3 4 5 |
# File 'lib/aqua/object/stub.rb', line 3 def path_from_parent @path_from_parent end |
Class Method Details
.aqua_init(init, opts = Translator::Opts.new) ⇒ Object
26 27 28 |
# File 'lib/aqua/object/stub.rb', line 26 def self.aqua_init( init, opts=Translator::Opts.new ) new( init ) end |