class Yokunai::AbstractController

Constants

DEFAULT_HEADERS

Constants


Public Class Methods

new(env, captures = nil) click to toggle source

@param env [Rack::Env] The Rack ENV @param captures [MatchData] The named captures from the route regex

# File lib/yokunai/abstract_controller.rb, line 18
def initialize(env, captures = nil)
  @env = env
  @captures = captures
  @templates = Yokunai::Template.new
end

Public Instance Methods

delete() click to toggle source
# File lib/yokunai/abstract_controller.rb, line 44
def delete
  unsupported_method
end
get() click to toggle source

Default HTTP method handlers


# File lib/yokunai/abstract_controller.rb, line 28
def get
  unsupported_method
end
options() click to toggle source
# File lib/yokunai/abstract_controller.rb, line 48
def options
  unsupported_method
end
patch() click to toggle source
# File lib/yokunai/abstract_controller.rb, line 40
def patch
  unsupported_method
end
post() click to toggle source
# File lib/yokunai/abstract_controller.rb, line 32
def post
  unsupported_method
end
put() click to toggle source
# File lib/yokunai/abstract_controller.rb, line 36
def put
  unsupported_method
end

Private Instance Methods

request() click to toggle source
# File lib/yokunai/abstract_controller.rb, line 75
def request
  @request ||= Rack::Request.new(@env)
end
respond(code: 200, headers: {}, body: "", template: nil, context: {}) click to toggle source
# File lib/yokunai/abstract_controller.rb, line 54
def respond(code: 200, headers: {}, body: "", template: nil, context: {})
  if template
    return respond_error(:not_found) unless @templates.exist?(template)
    body = @templates.render(template, context)
  end

  [
    code,
    DEFAULT_HEADERS.merge(headers),
    [body]
  ]
end
respond_error(meth) click to toggle source
# File lib/yokunai/abstract_controller.rb, line 67
def respond_error(meth)
  Yokunai::ErrorsController.new(@env).public_send(meth)
end
unsupported_method() click to toggle source
# File lib/yokunai/abstract_controller.rb, line 71
def unsupported_method
  [405, {}, ["Error 405: Method not supported on this resource.\n"]]
end