Class: Jetski::BaseController
- Inherits:
-
Object
- Object
- Jetski::BaseController
- Extended by:
- Helpers::RouteHelpers
- Includes:
- Frontend::JavascriptHelpers
- Defined in:
- lib/jetski/base_controller.rb
Constant Summary collapse
- RESERVED_INSTANCE_VARIABLES =
[ :@res, :@performed_render, :@action_name, :@controller_name, :@controller_path, :@cookies ]
Instance Attribute Summary collapse
-
#action_name ⇒ Object
Returns the value of attribute action_name.
-
#controller_name ⇒ Object
Returns the value of attribute controller_name.
-
#controller_path ⇒ Object
Returns the value of attribute controller_path.
-
#cookies ⇒ Object
Returns the value of attribute cookies.
-
#params ⇒ Object
Returns the value of attribute params.
-
#path ⇒ Object
writeonly
Sets the attribute path.
-
#performed_render ⇒ Object
readonly
Returns the value of attribute performed_render.
-
#request_method ⇒ Object
writeonly
Sets the attribute request_method.
-
#res ⇒ Object
readonly
Returns the value of attribute res.
-
#root ⇒ Object
writeonly
Sets the attribute root.
Instance Method Summary collapse
- #get_cookie(name) ⇒ Object
-
#initialize(res) ⇒ BaseController
constructor
A new instance of BaseController.
- #redirect_to(url) ⇒ Object
-
#render(**args) ⇒ Object
Method to render matching view with controller_name/action_name.
- #set_cookie(name, value) ⇒ Object
Methods included from Helpers::RouteHelpers
Methods included from Frontend::JavascriptHelpers
Constructor Details
#initialize(res) ⇒ BaseController
Returns a new instance of BaseController.
16 17 18 19 |
# File 'lib/jetski/base_controller.rb', line 16 def initialize(res) @res = res @performed_render = false end |
Instance Attribute Details
#action_name ⇒ Object
Returns the value of attribute action_name.
11 12 13 |
# File 'lib/jetski/base_controller.rb', line 11 def action_name @action_name end |
#controller_name ⇒ Object
Returns the value of attribute controller_name.
11 12 13 |
# File 'lib/jetski/base_controller.rb', line 11 def controller_name @controller_name end |
#controller_path ⇒ Object
Returns the value of attribute controller_path.
11 12 13 |
# File 'lib/jetski/base_controller.rb', line 11 def controller_path @controller_path end |
#cookies ⇒ Object
Returns the value of attribute cookies.
11 12 13 |
# File 'lib/jetski/base_controller.rb', line 11 def @cookies end |
#params ⇒ Object
Returns the value of attribute params.
11 12 13 |
# File 'lib/jetski/base_controller.rb', line 11 def params @params end |
#path=(value) ⇒ Object (writeonly)
Sets the attribute path
14 15 16 |
# File 'lib/jetski/base_controller.rb', line 14 def path=(value) @path = value end |
#performed_render ⇒ Object (readonly)
Returns the value of attribute performed_render.
13 14 15 |
# File 'lib/jetski/base_controller.rb', line 13 def performed_render @performed_render end |
#request_method=(value) ⇒ Object (writeonly)
Sets the attribute request_method
14 15 16 |
# File 'lib/jetski/base_controller.rb', line 14 def request_method=(value) @request_method = value end |
#res ⇒ Object (readonly)
Returns the value of attribute res.
13 14 15 |
# File 'lib/jetski/base_controller.rb', line 13 def res @res end |
#root=(value) ⇒ Object (writeonly)
Sets the attribute root
14 15 16 |
# File 'lib/jetski/base_controller.rb', line 14 def root=(value) @root = value end |
Instance Method Details
#get_cookie(name) ⇒ Object
50 51 52 |
# File 'lib/jetski/base_controller.rb', line 50 def (name) &.find { |c| c.name == name.to_s }&.value end |
#redirect_to(url) ⇒ Object
41 42 43 44 |
# File 'lib/jetski/base_controller.rb', line 41 def redirect_to(url) @performed_render = true res.set_redirect(WEBrick::HTTPStatus::Found, url) end |
#render(**args) ⇒ Object
Method to render matching view with controller_name/action_name
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/jetski/base_controller.rb', line 22 def render(**args) @performed_render = true request_status = args[:status] || 200 res.status = request_status if args[:text] res.content_type = "text/plain" res.body = "#{args[:text]}\n" return end if args[:json] res.content_type = "application/json" res.body = args[:json].to_json return end ViewRenderer.new(self).call end |
#set_cookie(name, value) ⇒ Object
46 47 48 |
# File 'lib/jetski/base_controller.rb', line 46 def (name, value) res..push WEBrick::Cookie.new(name.to_s, value || "") end |