Class: SanaController

Inherits:
Object
  • Object
show all
Defined in:
lib/sana_controller.rb

Overview

Sana Controller

Direct Known Subclasses

SanaAnyEventController

Defined Under Namespace

Classes: Params

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(events, event_id, request, mapping = {}) ⇒ SanaController

constructor

Parameters:

  • events (SanaRouter::Events)

    events

  • event_id (Symbol)

    event id

  • request (OpenStruct)

    request

  • mapping (Hash<Symbol, Integer>) (defaults to: {})

    request argument mappings


8
9
10
11
12
13
# File 'lib/sana_controller.rb', line 8

def initialize(events, event_id, request, mapping = {})
  @events = events
  @event_id = event_id
  @request = request
  @mapping = mapping
end

Instance Attribute Details

#event_idSymbol (readonly)

event id

Returns:

  • (Symbol)

20
21
22
# File 'lib/sana_controller.rb', line 20

def event_id
  @event_id
end

#eventsSanaRouter::Events (readonly)

events

Returns:


17
18
19
# File 'lib/sana_controller.rb', line 17

def events
  @events
end

#requestOpenStruct (readonly)

request

Returns:

  • (OpenStruct)

23
24
25
# File 'lib/sana_controller.rb', line 23

def request
  @request
end

Instance Method Details

#actionString, Openstruct

exec action and get response

Returns:

  • (String, Openstruct)

    response


33
34
35
36
37
38
39
40
# File 'lib/sana_controller.rb', line 33

def action
  @return_value = public_send(@event_id)
  if @response
    @response
  else
    render
  end
end

#paramsSanaController::Params

named access to request headers

Returns:


27
28
29
# File 'lib/sana_controller.rb', line 27

def params
  @params ||= Params.new(request, @mapping)
end