Class: Easy::Api::BlockWrapper::Wrapper
- Inherits:
-
Object
- Object
- Easy::Api::BlockWrapper::Wrapper
- Defined in:
- lib/easy/api/block_wrapper.rb
Overview
A class to encapulate the API code so it can be called from the block.
Instance Method Summary collapse
-
#initialize(controller) ⇒ Wrapper
constructor
A new instance of Wrapper.
-
#method_missing(name, *args, &block) ⇒ Object
Delegate other method calls to the result object.
-
#render_result(render_params) ⇒ Object
use the controller to render the response.
Constructor Details
#initialize(controller) ⇒ Wrapper
Returns a new instance of Wrapper.
20 21 22 23 |
# File 'lib/easy/api/block_wrapper.rb', line 20 def initialize(controller) @controller = controller @result ||= Easy::Api::Result.new end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
Delegate other method calls to the result object
42 43 44 |
# File 'lib/easy/api/block_wrapper.rb', line 42 def method_missing(name, *args, &block) @result.send(name, *args, &block) end |
Instance Method Details
#render_result(render_params) ⇒ Object
use the controller to render the response
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/easy/api/block_wrapper.rb', line 26 def render_result(render_params) format = (render_params[:format] || 'json').try(:to_sym) formatted_result = if format == :xml @result.to_xml(render_params[:options] || {}) else @result end if render_params[:callback].blank? @controller.render(format => formatted_result, :status => @result.status_code) else @controller.render(format => formatted_result, :status => @result.status_code, :callback => render_params[:callback], :content_type => 'application/javascript') end end |