class SanaController

Sana Controller

Attributes

event_id[R]

event id @return [Symbol]

events[R]

events @return [SanaRouter::Events]

request[R]

request @return [OpenStruct]

Public Class Methods

new(events, event_id, request, mapping = {}) click to toggle source

constructor @param [SanaRouter::Events] events events @param [Symbol] event_id event id @param [OpenStruct] request request @param [Hash<Symbol, Integer>] mapping request argument mappings

# File lib/sana_controller.rb, line 10
def initialize(events, event_id, request, mapping = {})
  @events = events
  @event_id = event_id
  @request = request
  @mapping = mapping
end

Public Instance Methods

action() click to toggle source

exec action and get response @return [String, Openstruct] response

# File lib/sana_controller.rb, line 35
def action
  @return_value = public_send(@event_id)
  if @response
    @response
  else
    render
  end
end
params() click to toggle source

named access to request headers @return [SanaController::Params] params

# File lib/sana_controller.rb, line 29
def params
  @params ||= Params.new(request, @mapping)
end

Private Instance Methods

render(*args) click to toggle source

render result @param args various result options @return [String, Openstruct] response

# File lib/sana_controller.rb, line 49
def render(*args)
  @response = render_response(*args)
end
render_bad_request() click to toggle source

render 400 Bad Request @return [OpenStruct] response

# File lib/sana_controller.rb, line 69
def render_bad_request
  @response = Sana::ResponseHelper.bad_request
end
render_internal_server_error() click to toggle source

render 500 Internal Server Error @return [OpenStruct] response

# File lib/sana_controller.rb, line 75
def render_internal_server_error
  @response = Sana::ResponseHelper.internal_server_error
end
render_no_content() click to toggle source

render 204 No Content @return [OpenStruct] response

# File lib/sana_controller.rb, line 63
def render_no_content
  @response = Sana::ResponseHelper.no_content
end
render_ok(value = nil, to = nil) click to toggle source

render raw normal response (200 OK or 204 No Content) @param [String] value Value header content @param [String] to Reference0 header content (for communication) @return [OpenStruct] response

# File lib/sana_controller.rb, line 57
def render_ok(value = nil, to = nil)
  @response = Sana::ResponseHelper.ok(value, to)
end
render_response(*args) click to toggle source

make result by given options @param args various result options @return [String, Openstruct] response @note this method should be overridden for convenient view rendering @example override

class HogeViewController < SanaController
  def render_response(value = nil)
    # @return_value is event method's return value
    eval (value || @return_value)
  end
end
# File lib/sana_controller.rb, line 90
def render_response(*args)
  args[0] || @return_value
end