Class: Easy::Api::BlockWrapper::Wrapper

Inherits:
Object
  • Object
show all
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

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



36
37
38
# File 'lib/easy/api/block_wrapper.rb', line 36

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
# File 'lib/easy/api/block_wrapper.rb', line 26

def render_result(render_params)
  format = (render_params[:format] || 'json').try(:to_sym)
  if render_params[:callback].blank?
    @controller.render(format => @result, :status => @result.status_code)
  else
    @controller.render(format => @result, :status => @result.status_code, :callback => render_params[:callback], :content_type => 'application/javascript')
  end
end