Class: K8::BaseAction

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

Overview

Equivarent to BaseController or AbstractRequestHandler in other framework.

Direct Known Subclasses

Action

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(req, resp) ⇒ BaseAction

Returns a new instance of BaseAction.



729
730
731
732
733
734
735
# File 'lib/keight.rb', line 729

def initialize(req, resp)
  #; [!uotpb] accepts request and response objects.
  @req  = req
  @resp = resp
  #; [!7sfyf] sets session object.
  @sess = req.env['rack.session']
end

Instance Attribute Details

#reqObject (readonly)

Returns the value of attribute req.



737
738
739
# File 'lib/keight.rb', line 737

def req
  @req
end

#respObject (readonly)

Returns the value of attribute resp.



737
738
739
# File 'lib/keight.rb', line 737

def resp
  @resp
end

#sessObject (readonly)

Returns the value of attribute sess.



737
738
739
# File 'lib/keight.rb', line 737

def sess
  @sess
end

Instance Method Details

#handle_action(action_method, urlpath_params) ⇒ Object



739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
# File 'lib/keight.rb', line 739

def handle_action(action_method, urlpath_params)
  @current_action = action_method
  ex = nil
  begin
    #; [!5jnx6] calls '#before_action()' before handling request.
    before_action()
    #; [!ddgx3] invokes action method with urlpath params.
    content = invoke_action(action_method, urlpath_params)
    #; [!aqa4e] returns content.
    return handle_content(content)
  rescue Exception => ex
    raise
  ensure
    #; [!67awf] calls '#after_action()' after handling request.
    #; [!alpka] calls '#after_action()' even when error raised.
    after_action(ex)
  end
end