Class: Sequencescape::Api::ResourceModelProxy
- Inherits:
-
Object
- Object
- Sequencescape::Api::ResourceModelProxy
- Extended by:
- Actions
- Includes:
- FinderMethods
- Defined in:
- lib/sequencescape-api/resource_model_proxy.rb
Overview
Any interaction with the API isn’t done directly through a model but through an instance of this class, that proxies the model and ensures that it uses the correct instance of Sequencescape::Api.
Instance Method Summary collapse
-
#initialize(api, model, actions) ⇒ ResourceModelProxy
constructor
A new instance of ResourceModelProxy.
- #is_a_proxied_model? ⇒ Boolean
- #respond_to_missing?(name, include_private = false) ⇒ Boolean
Methods included from Actions
Methods included from FinderMethods
#all, extended, #find, included
Constructor Details
#initialize(api, model, actions) ⇒ ResourceModelProxy
Returns a new instance of ResourceModelProxy.
16 17 18 19 20 21 |
# File 'lib/sequencescape-api/resource_model_proxy.rb', line 16 def initialize(api, model, actions) @api = api @model = model @actions = OpenStruct.new(actions) @model.send(:initialize_class_actions, self) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object (protected)
35 36 37 |
# File 'lib/sequencescape-api/resource_model_proxy.rb', line 35 def method_missing(name, *args, &block) model.send(name, api, *args, &block) end |
Instance Method Details
#is_a_proxied_model? ⇒ Boolean
40 41 42 |
# File 'lib/sequencescape-api/resource_model_proxy.rb', line 40 def is_a_proxied_model? true end |
#respond_to_missing?(name, include_private = false) ⇒ Boolean
31 32 33 |
# File 'lib/sequencescape-api/resource_model_proxy.rb', line 31 def respond_to_missing?(name, include_private = false) super or model.respond_to?(name, include_private) end |