Class: Ubicloud::ModelAdapter
- Inherits:
-
Object
- Object
- Ubicloud::ModelAdapter
- Defined in:
- lib/ubicloud/model_adapter.rb
Overview
Ubicloud::ModelAdapter instances represents a model class that is tied to a adapter. Methods called on instances of this class are forwarded to the related model, with the adapter as the first argument.
Instance Method Summary collapse
-
#initialize(model, adapter) ⇒ ModelAdapter
constructor
A new instance of ModelAdapter.
-
#method_missing(meth) ⇒ Object
Forward methods to the model class, but include the adapter as the first argument.
-
#respond_to_missing? ⇒ Boolean
Respond to the method if the model class responds to it.
Constructor Details
#initialize(model, adapter) ⇒ ModelAdapter
Returns a new instance of ModelAdapter.
9 10 11 12 |
# File 'lib/ubicloud/model_adapter.rb', line 9 def initialize(model, adapter) @model = model @adapter = adapter end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth) ⇒ Object
Forward methods to the model class, but include the adapter as the first argument.
16 17 18 |
# File 'lib/ubicloud/model_adapter.rb', line 16 def method_missing(meth, ...) @model.public_send(meth, @adapter, ...) end |
Instance Method Details
#respond_to_missing? ⇒ Boolean
Respond to the method if the model class responds to it.
21 22 23 |
# File 'lib/ubicloud/model_adapter.rb', line 21 def respond_to_missing?(...) @model.respond_to?(...) end |